'声明API函数
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
'用sndPlaySound播放
Call sndPlaySound("C:\test.wav", SND_ASYNC)
'SND_ASYNC异步播放,SND_SYNC同步播放,好像没什么区别,也可以和下面一样用数字,1应该是代表异步播放。
'用PlaySound播放
'Call PlaySound("C:\test.wav", 0, 8)
'参数1为wav文件名,参数2必须取0,参数3取1表示后台播放,取8表示循环播放,因此取9(=1+8)表示在后台循环播放。
'参数3写8不能循环播放,只有写9,在后台循环播放
End Sub
Private Sub Command4_Click()
Call sndPlaySound(" ", 1)'让sndPlaySound停止播放,其实就是让它播放一个不存在的文件,然后就终止了。
'Call PlaySound(" ", 0, 1)
End Sub
-----------------------------------------------------
如果不设置后台播放,窗体会不能操作,sndPlaySound和PlaySound都只适合播放小音频的播放,因为它们是把文件读入内存,再播放的,所以很占资源。
联系客服