Multiple Sounds in VB6
is it possible to play multiple .wav sounds (that may also overlap) in VB6, maybe through API calls and without DirectSound?
if you use the functions below that use the mciSendString api, and open each .wav file using a different Alias, you have complete control over each individual .wav sound. Also, if you call StopSound, it acts like pause, so calling PlaySound resumes play where it left off.
Here you go:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hWndCallback As Long) As Long
Dim lRet As String
Private Function OpenSound(TrackPath, Alias)
mciSendString "open """ & TrackPath & """ alias " & Alias, lRet, Len(lRet), 0
Private Function PlaySound(Alias)
mciSendString "play " & Alias, lRet, Len(lRet), 0
Private Function StopSound(Alias)
mciSendString "stop " & Alias, lRet, Len(lRet), 0
Private Function CloseSound(Alias)
mciSendString "close " & Alias, lRet, Len(lRet), 0
there are a lot more things possible such as left and right volume changing, starting play from a certain location, retrieving play location and playing cd-audio and videos!
hope it helps.
it will surely help!
Thank you very much, I'll try it as soon as possible.
Hi tanelorn, sorry to bother you again... (wish you are still online)!
This code is exactly what I need but when a sound has been played, I am not able to re-play it again.
Should I "rewind" it in any way or should I close and then re-open it?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center