Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing sound overlap 1

Status
Not open for further replies.

mbrink

Technical User
Jul 5, 2002
13
US
My program plays sounds (WAV files using MS Multimedia Control) for various events. However, frequently events promting a sound occur in rapid succession in the code.

The two ways I've figured out:
1. Each sound stops the previous one before playing, resulting in only the last one in the order being heard.
2. All of them play over each other.

I need some way to get the computer to wait for the first sound to play before the second one starts. Ideally, it should pause the entire program while the sounds are playing.
 
Use an API call to play the wave files:

Code:
'********************
'       SOUND CONSTANTS
'********************
Public Const SND_ASYNC = &H1      '  play asynchronously
Public Const SND_LOOP = &H8       '  loop the sound until next 
Public Const SND_NODEFAULT = &H2  '  silence not default, if not found
Public Const SND_NOSTOP = &H10    '  don't stop currently playing sound
Public Const SND_NOWAIT = &H2000  '  don't wait if busy
Public Const SND_SYNC = &H0       '  play synchronously (default)
Public Const SND_ALIAS = &H10000  '  name is a [sounds] entry

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
                  (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

' Playing synchronously will halt code until finished.
Call sndPlaySound("C:\myWave.wav", SND_SYNC Or SND_NOSTOP)
VBSlammer
redinvader3walking.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top