这是我第一次寻求帮助。
我已经检查了很多网站,甚至通过维也纳大学的 WaybackMachine for Excel 文件,但我没有找到解决方案。我已经检查了winmm.dll API的函数,如sndPlaySoundA和mciSendStringA。
我能够播放异步循环的 WAV 文件,但目前无法同时播放另一个异步循环的文件。如下所示,可以组合启用循环和异步的标志。我尝试将其与另一个标志组合,但没有结果我想要。
Private Declare Function PlaySound Lib "winmm" Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_LOOP = &H8
Private Const SND_NODEFAULT = &H2
Private Sub LoopTrack(ByVal sTrack As String)
Dim lReturnValue As Long
lReturnValue = PlaySound(sTrack, SND_ASYNC Or SND_LOOP)
If lReturnValue = 0 Then MsgBox "Can't play " & sTrack
End Sub
Public Sub PlayBackStop()
Call PlayTrack(vbNullString)
End Sub
Private Sub PlayTrack(ByVal sTrack As String)
Dim lReturnValue As Long
lReturnValue = PlaySound(sTrack, SND_ASYNC Or SND_NODEFAULT)
If lReturnValue = 0 Then MsgBox "Can't play " & sTrack
End Sub
我还尝试了下面的代码,该代码异步播放多个文件但不循环。知道如何异步循环多个文件并控制它们吗?
Private Declare Function SendString Lib "winmm" Alias "mciSendStringA" ( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Public Sub PlayMultimedia( _
ByVal sAliasName As String, _
Optional ByVal sFirstFrame As String = vbNullString, _
Optional ByVal sLastFrame As String = vbNullString)
If sFirstFrame = vbNullString Then sFirstFrame = 0
If sLastFrame = vbNullString Then sLastFrame = GetTotalFrames(sAliasName)
Dim sToDo As String * 128
Dim lReturnValue As Long
Dim sErrorToReturn As String * 128
sToDo = "play " & sAliasName & " from " & sFirstFrame & " to " & sLastFrame
lReturnValue = SendString(sToDo, 0&, 0&, 0&)
If Not lReturnValue = 0 Then
GetError lReturnValue, sErrorToReturn, 128
MsgBox sErrorToReturn
End
End If
End Sub
Public Function GetTotalFrames(ByVal sAliasX As String) As Long
Dim lReturnValue As Long
Dim sTotalFrames As String * 128
lReturnValue = SendString("set " & sAliasX & " time format frames", sTotalFrames, 128, 0&)
lReturnValue = SendString("status " & sAliasX & " length", sTotalFrames, 128, 0&)
If Not lReturnValue = 0 Then
GetTotalFrames = -1
Exit Function
End If
GetTotalFrames = Val(sTotalFrames)
End Function
尝试使用WMPlayer.OCX
,下面是示例:
Dim wmp1
Dim wmp2
Sub test()
Set wmp1 = CreateObject("new:6BF52A52-394A-11D3-B153-00C04F79FAA6")
With wmp1
.url = "C:Testsound1.wav"
.controls.play
.settings.playCount = 5
End With
Set wmp2 = CreateObject("new:6BF52A52-394A-11D3-B153-00C04F79FAA6")
With wmp2
.url = "C:Testsound2.mp3"
.controls.play
.settings.setMode "loop", True
End With
End Sub
顺便说一句,Set wmp1 = CreateObject("WMPlayer.OCX")
和Set wmp1 = New WMPLib.WindowsMediaPlayer
参考C:WindowsSystem32wmp.dll
对我不起作用,这就是我使用new:
绰号的原因。