Multiple Sounds in VB6


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Multiple Sounds in VB6

  1. #1
    Join Date
    Jul 2005
    Posts
    4

    Post Multiple Sounds in VB6

    Hi there,
    is it possible to play multiple .wav sounds (that may also overlap) in VB6, maybe through API calls and without DirectSound?
    Thank you.
    Gizah

  2. #2
    Join Date
    Jul 2005
    Posts
    3
    hi Gizah,

    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
    End Function

    Private Function PlaySound(Alias)
    mciSendString "play " & Alias, lRet, Len(lRet), 0
    End Function

    Private Function StopSound(Alias)
    mciSendString "stop " & Alias, lRet, Len(lRet), 0
    End Function

    Private Function CloseSound(Alias)
    mciSendString "close " & Alias, lRet, Len(lRet), 0
    End Function

    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.

  3. #3
    Join Date
    Jul 2005
    Posts
    4
    Dear tanelorn,
    it will surely help!
    Thank you very much, I'll try it as soon as possible.
    Ciao

  4. #4
    Join Date
    Jul 2005
    Posts
    4
    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?

    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center