播放wav文件,同步程序卡顿,异步不播放的问题

zhangyangziwo 2014-07-17 04:11:50
使用api,sndPlaySoundA播放wav文件
参数
0 - 同步播放
1 - 异步播放
2 - 如果找不到声音文件,不使用缺省的声音文件
3 - 第1项与第2项
8 - 循环播放直到下一个sndPlaysound
10- 不停止播放
返回值:
0 出错(通常是文件没有找到)
1 成功

同步播放时,因为需要等待播放完毕,才能继续执行程序,所以出现卡顿的情况。
异步播放时,如果只执行一次函数,表现是很好的,程序能继续操作,声音也能播放
但是如果循环执行多次函数,就会出现不播放声音的问题

请问大家有没有方法,程序既能正常操作,声音也能正常播放?

百度的时候,发现有人咨询,将多个wav文件合并成一个文件,然后在播放的
...全文
630 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
bombshell 2014-07-19
  • 打赏
  • 举报
回复
15. openState Player.openState The openState property retrieves a value indicating the state of the content source. Syntax player.openState Possible Values This property is a read only Number (long). The C-style enumeration constant can be derived by prefixing the state value with "wmpos". For example, the constant for the PlaylistOpening state is wmposPlaylistOpening. Value State Description 0 Undefined Windows Media Player is in an undefined state. 1 PlaylistChanging New playlist is about to be loaded. 2 PlaylistLocating Windows Media Player is attempting to locate the playlist. The playlist can be local (Media Library or metafile with a .asx file name extension) or remote. 3 PlaylistConnecting Connecting to the playlist. 4 PlaylistLoading Playlist has been found and is now being retrieved. 5 PlaylistOpening Playlist has been retrieved and is now being parsed and loaded. 6 PlaylistOpenNoMedia Playlist is open. 7 PlaylistChanged A new playlist has been assigned to currentPlaylist. 8 MediaChanging A new media item is about to be loaded. 9 MediaLocating Windows Media Player is locating the media item. The file can be local or remote. 10 MediaConnecting Connecting to the server that holds the media item. 11 MediaLoading Media item has been located and is now being retrieved. 12 MediaOpening Media item has been retrieved and is now being opened. 13 MediaOpen Media item is now open. 14 BeginCodecAcquisition Starting codec acquisition. 15 EndCodecAcquisition Codec acquisition is complete. 16 BeginLicenseAcquisition Acquiring a license to play DRM protected content. 17 EndLicenseAcquisition License to play DRM protected content has been acquired. 18 BeginIndividualization Begin DRM Individualization. 19 EndIndividualization DRM individualization has been completed. 20 MediaWaiting Waiting for media item. 21 OpeningUnknownURL Opening a URL with an unknown type. Remarks Windows Media Player states are not guaranteed to occur in any particular order. Furthermore, not every state necessarily occurs during a sequence of events. You should not write code that relies upon state order. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 16. playerApplication Player.playerApplication The playerApplication property retrieves the PlayerApplication object when a remoted Windows Media Player control is running. Syntax playerApplication Possible Values This property is a read-only PlayerApplication object or the null value. Remarks This property is used only when remoting the Windows Media Playercontrol. If the value is null, the Windows Media Playercontrol is not embedded in remote mode. This property is only accessible in C++ code or in script code in skins through the playerApplication global variable. Requirements Version: Windows Media Player 9 Series or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 17. playlistCollection Player.playlistCollection The playlistCollection property retrieves the PlaylistCollection object. Syntax player.playlistCollection Possible Values This property is a read-only PlaylistCollection object. Remarks To retrieve the value of this property, read access to Media Library is required. For more information, see Media Library Access. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 18. playState Player.playState The playState property retrieves a value indicating the state of the Windows Media Player operation. Syntax player.playState Possible Values This property is a read-only Number (long). The C-style enumeration constant can be derived by prefixing the state value with "wmpps". For example, the constant for the Playing state is wmppsPlaying. Value State Description 0 Undefined Windows Media Player is in an undefined state. 1 Stopped Playback of the current media item is stopped. 2 Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location. 3 Playing The current media item is playing. 4 ScanForward The current media item is fast forwarding. 5 ScanReverse The current media item is fast rewinding. 6 Buffering The current media item is getting additional data from the server. 7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin. 8 MediaEnded Media item has completed playback. 9 Transitioning Preparing new media item. 10 Ready Ready to begin playing. 11 Reconnecting Reconnecting to stream. Remarks Windows Media Player states are not guaranteed to occur in any particular order. Furthermore, not every state necessarily occurs during a sequence of events. You should not write code that relies upon state order. Example Code The following JScript code shows the use of the player.playState property. An HTML text element, named "myText", displays the current status. The Player object was created with ID = "Player". // Test whether Windows Media Player is in the playing state. if (3 == Player.playState) myText.value = "Windows Media Player is playing!"; else myText.value = "Windows Media Player is NOT playing!"; Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 19. settings Player.settings The settings property retrieves the Settings object. Syntax player.settings Possible Values This property is a read-only Settings object. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll.
bombshell 2014-07-19
  • 打赏
  • 举报
回复
7. enableContextMenu Player.enableContextMenu The enableContextMenu property specifies or retrieves a value indicating whether to enable the context menu, which appears when the right mouse button is clicked. Syntax player.enableContextMenu Possible Values This property is a read/write Boolean. Value Description true Default. Enable the context menu. false Do not enable the context menu. Remarks During full-screen playback, Windows Media Player hides the mouse cursor when enableContextMenu equals false and uiMode equals "none". Windows Media Player 10 Mobile: This property is not supported. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 8. enabled Player.enabled The enabled property specifies or retrieves a value indicating whether the Windows Media Player control is enabled. Syntax player.enabled Possible Values This property is a read/write Boolean. Value Description true Default. The Windows Media Player control is enabled. false The Windows Media Player control is disabled. Remarks If enabled equals false then during full-screen playback Windows Media Player hides the user controls. 当enabled 属性等于false那么全屏播放的media player 控件隐藏用户控制 Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 9. error Player.error The error property retrieves the Error object. Syntax player.error Possible Values This property is a read-only Error object. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 10. fullScreen Player.fullScreen The fullScreen property specifies or retrieves a value indicating whether video content is played back in full-screen mode. Syntax player.fullScreen Possible Values This property is a read/write Boolean. Value Description true Video content is played back in full-screen mode. false Default. Video content is not played back in full-screen mode. Remarks For full-screen mode to work properly when embedding the Windows Media Player control, the video display area must have a height and width of at least one pixel. If uiMode is set to "mini" or "full", the height of the control itself must be 65 or greater to accommodate the video display area in addition to the user interface. If uiMode is set to "invisible", then setting this property to true raises an error and does not affect the behavior of the control. During full-screen playback, Windows Media Player hides the mouse cursor when enableContextMenu equals false and uiMode equals "none". If uiMode is set to "full" or "mini", Windows Media Player displays transport controls in full-screen mode when the mouse cursor moves. After a brief interval of no mouse movement, the transport controls are hidden. If uiMode is set to "none", no controls are displayed in full-screen mode. Note Displaying transport controls in full-screen mode requires the Windows XP operating system. If transport controls are not displayed in full-screen mode, then Windows Media Player automatically exits full-screen mode when playback stops. Example Code The following example creates an HTML input button that uses Player.fullScreen to switch an embedded player object to full-screen mode. The Player object was created with ID = "Player". <INPUT type = button value = "Full Screen" name = FSBUTTON onclick = " /* Check to be sure the player is playing. */ if (Player.playState == 3) Player.fullScreen = 'true'; "> Note Always be sure to inform the user how to return from full-screen mode. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 11. isOnline Player.isOnline The isOnline property retrieves a value indicating whether the user is connected to a network. Syntax player.isOnline Possible Values This property is a read-only Boolean. Value Description true The user is connected to a network. false The user is not connected to a network. Remarks Windows Media Player 10 Mobile: This property always returns true. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 12. isRemote Player.isRemote The isRemote property retrieves a value indicating whether the Windows Media Player control is running in remote mode. Syntax player.isRemote Possible Values This property is a read-only Boolean. Value Description true The Player control is running in remote mode. false The Player control is running in local mode. Remarks Windows Media Player 10 Mobile: This property always returns false. Requirements Version: Windows Media Player 9 Series or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 13. mediaCollection Player.mediaCollection The mediaCollection property retrieves the MediaCollection object. Syntax player.mediaCollection Possible Values This property is a read-only MediaCollection object. Remarks To retrieve the value of this property, read access to Media Library is required. For more information, see Media Library Access. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 14. network Player.network The network property retrieves the Network object. Syntax player.network Possible Values This property is a read-only Network object. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll.
bombshell 2014-07-19
  • 打赏
  • 举报
回复
Player Object The Player object is the root object for the Windows Media Player control. It supports the properties, methods, and events listed in the following tables. The Player object supports the following properties. Properties marked with an asterisk (*) are not accessible to skins. Property Description cdromCollection Retrieves the CdromCollection object. closedCaption Retrieves the ClosedCaption object. controls Retrieves the Controls object. currentMedia Specifies or retrieves the current Media object. currentPlaylist Specifies or retrieves the current Playlist object. dvd Retrieves the DVD object. enableContextMenu * Specifies or retrieves a value indicating whether to enable the context menu, which appears when the right mouse button is clicked. enabled * Specifies or retrieves a value indicating whether the Windows Media Player control is enabled. error Retrieves the Error object. fullScreen * Specifies or retrieves a value indicating whether video content is played back in full-screen mode. isOnline Retrieves a value indicating whether the user is connected to a network. isRemote * Retrieves a value indicating whether the Windows Media Player control is running in remote mode. mediaCollection Retrieves the MediaCollection object. network Retrieves the Network object. openState Retrieves a value indicating the state of the content source. playerApplication * Retrieves the PlayerApplication object when a remoted Windows Media Player control is running. playlistCollection Retrieves the PlaylistCollection object. playState Retrieves a value indicating the state of the Windows Media Player operation. settings Retrieves the Settings object. status Retrieves a value indicating the current status of Windows Media Player. stretchToFit * Specifies or retrieves a value indicating whether video will stretch to fit size of the Windows Media Player control video display. uiMode * Specifies or retrieves a value indicating which controls are shown in the user interface when Windows Media Player is embedded in a Web page. URL Specifies or retrieves the name of the clip to play. versionInfo Retrieves a String value specifying the version of the Windows Media Player. windowlessVideo * Specifies or retrieves a value indicating whether the Windows Media Player control renders video in windowless mode. * Not accessible to skins. The Player object supports the following methods. Method Description close Releases Windows Media Player resources. launchURL Sends a URL to the user's default browser to be rendered. newMedia Creates a new Media object. newPlaylist Creates a new Playlist object. openPlayer Opens Windows Media Player using the specified URL. The Player object supports the following events. Events marked with an asterisk (*) are not accessible to skins. For information about handling mouse and keyboard events in skins, see External Events. Event Description AudioLanguageChange Occurs when the current audio language changes. Buffering Occurs when the Windows Media Player control begins or ends buffering. CdromMediaChange Occurs when a CD or DVD is inserted into or ejected from a CD or DVD drive. Click * Occurs when the user clicks a mouse button. CurrentItemChange Occurs when Controls.currentItem changes. CurrentMediaItemAvailable Occurs when a graphic metadata item in the current media item becomes available. CurrentPlaylistChange Occurs when something changes within the current playlist. CurrentPlaylistItemAvailable Occurs when the current playlist item becomes available. Disconnect Reserved for future use. DomainChange Occurs when the DVD domain changes. DoubleClick * Occurs when the user double-clicks a mouse button. DurationUnitChange Reserved for future use. EndOfStream Reserved for future use. Error Occurs when the Windows Media Player control has an error condition. KeyDown * Occurs when a key is pressed. KeyPress * Occurs when a key is pressed and then released. KeyUp * Occurs when a key is released. MarkerHit Occurs when a marker is reached. MediaChange Occurs when a media item changes. MediaCollectionAttributeStringAdded Occurs when an attribute value is added to Media Library. MediaCollectionAttributeStringChanged Occurs when an attribute value in Media Library is changed. MediaCollectionAttributeStringRemoved Occurs when an attribute value is removed from Media Library. MediaCollectionChange Occurs when the media collection changes. MediaError Occurs when the Media object has an error condition. ModeChange Occurs when a mode of Windows Meida Player is changed. MouseDown * Occurs when a mouse button is pressed. MouseMove * Occurs when the mouse pointer is moved. MouseUp * Occurs when a mouse button is released. NewStream Reserved for future use. OpenPlaylistSwitch Occurs when a title on a DVD begins playing. OpenStateChange Occurs when the Windows Media Player control changes state. PlaylistChange Occurs when a playlist changes. PlaylistCollectionChange Occurs when something changes in the playlist collection. PlaylistCollectionPlaylistAdded Occurs when a playlist is added to the playlist collection. PlaylistCollectionPlaylistRemoved Occurs when a playlist is removed from the playlist collection. PlaylistCollectionPlaylistSetAsDeleted Reserved for future use. PlayStateChange Occurs when the play state of the Windows Media Player control changes. PositionChange Occurs when the current position of the media item has been changed. ScriptCommand Occurs when a synchronized command or URL is received. StatusChange Occurs when the status property changes value. Warning Reserved for future use. * Not accessible to skins. For information about handling mouse and keyboard events in skins, see Ambient Event Handlers. When embedded in a Web page, the Player object can be accessed by using the ID value specified in the OBJECT tag. Within a skin definition file, it is accessed by using the player global attribute. For illustration purposes, player will be used as the object ID in the reference syntax sections. 1. cdromCollection Player.cdromCollection The cdromCollection property retrieves the CdromCollection object. Syntax player.cdromCollection Possible Values This property is a read-only CdromCollection object. Remarks To retrieve the value of this property, read access to Media Library is required. For more information, see Media Library Access. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 2. closedCaption Player.closedCaption The closedCaption property retrieves the ClosedCaption object. Syntax player.closedCaption Possible Values This property is a read-only ClosedCaption object. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 3. controls Player.controls The controls property retrieves the Controls object. Syntax player.controls Possible Values This property is a read-only Controls object. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 4. currentMedia Player.currentMedia The currentMedia property specifies or retrieves the current Media object. Syntax player.currentMedia Possible Values This property is a read/write Media object. Remarks If the Settings.autoStart property is true, playback begins automatically whenever you set currentMedia. This property takes a Media object, which can be acquired by using Playlist.item. To load a Media item using a file name, set the URL property or use newMedia. Example Code The following JScript example retrieves the first media item in Media Library. It then uses currentMedia to make the retrieved media item the current media item, and then to display the name of the current media item. The Player object was created with ID = "Player". // Retrieve the first media item from Media Library var firstMedia = Player.mediaCollection.getAll().item(0); // Make the retrieved media item the current media item. Player.currentMedia = firstMedia; // Display the name of the current media item. document.write("Found first media item. Name = " + Player.currentMedia.name); Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 5. currentPlaylist Player.currentPlaylist The currentPlaylist property specifies or retrieves the current Playlist object. Syntax player.currentPlaylist Possible Values This property is a read/write Playlist object. Remarks If the Settings.autoStart property is true, playback begins automatically whenever you set currentPlaylist. This property takes a Playlist object, which can be acquired in several ways, such as by calling PlaylistArray.item or PlaylistCollection.newPlaylist. To load a Playlist item using a file name, set the URL property or use Player.newPlaylist. Example Code The following JScript example retrieves the first playlist in Media Library. It then uses currentPlaylist to make the retrieved playlist the current playlist, and then to display the name of the current playlist. The Player object was created with ID = "Player". // Retrieve the first playlist from Media Library. var firstPL = Player.playlistCollection.getAll().item(0); // Make the retrieved playlist the current playlist. Player.currentPlaylist = firstPL; // Display the name of the current playlist. document.write("Found first playlist. Name: " + Player.currentPlaylist.name); Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll. 6. dvd Player.dvd The dvd property retrieves the DVD object. Syntax player.dvd Possible Values This property is a read-only DVD object. Requirements Version: Windows Media Player version 7.0 or later. Header: Defined in wmp.idl; include wmp.h. Library: Use wmp.dll.
lztqy 2014-07-19
  • 打赏
  • 举报
回复
牛逼!!!!!!!!!!
WorldMobile 2014-07-18
  • 打赏
  • 举报
回复
引用 楼主 zhangyangziwo 的回复:
使用api,sndPlaySoundA播放wav文件 参数 0 - 同步播放 1 - 异步播放 2 - 如果找不到声音文件,不使用缺省的声音文件 3 - 第1项与第2项 8 - 循环播放直到下一个sndPlaysound 10- 不停止播放 返回值: 0 出错(通常是文件没有找到) 1 成功 同步播放时,因为需要等待播放完毕,才能继续执行程序,所以出现卡顿的情况。 异步播放时,如果只执行一次函数,表现是很好的,程序能继续操作,声音也能播放 但是如果循环执行多次函数,就会出现不播放声音的问题 请问大家有没有方法,程序既能正常操作,声音也能正常播放? 百度的时候,发现有人咨询,将多个wav文件合并成一个文件,然后在播放的
两种解决方案,如果用同步,肯定会有卡顿,建议控制一下,等播放完一个再播放下一个 如果用异步,你需要做的工作时不要一下子全调用,通过yield为控制一下,等播放结束后再调用下一个,就不会出现你说的问题了,否则肯定只播放最后一个,我以前用过
zhangyangziwo 2014-07-18
  • 打赏
  • 举报
回复
利用ole,当使用play函数时,pb会报错 提示无效的函数呢 哪位高手处理过这个问题啊
zhangyangziwo 2014-07-18
  • 打赏
  • 举报
回复
搜到一个02年的帖子,将如何将pb暂停的 http://bbs.csdn.net/topics/444060 学到一个方法 一个yield是不起作用的,需要不断地循环执行yield long ll_start ll_start = cpu() do while 1 = 1 yield() if cpu() - ll_start > 5000 then exit loop 这样处理之后,好多了,不至于程序卡顿啦
zhangyangziwo 2014-07-18
  • 打赏
  • 举报
回复
我是通过循环去播放金额的 比如135.5 一百三拾五元五角 就会循环8次,执行8次 异步调用 将yield放到循环体内,没发现有效果呢
zhangyangziwo 2014-07-17
  • 打赏
  • 举报
回复
嗯,正在看media player 请问,它会不会占用资源比较大? 还没找到它的帮助,不知道方法和属性
bombshell 2014-07-17
  • 打赏
  • 举报
回复
可以考虑一下使用media player 控件
zhangyangziwo 2014-07-17
  • 打赏
  • 举报
回复
更准确的描述,如果是异步播放,循环执行函数,只有最后一次执行播放声音

740

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 脚本语言
社区管理员
  • 脚本语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧