Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

Play 2 short sounds in a row vb6

The sounds are loaded from a resource file
I am trying to play 2 sounds in a row the code below skips the first sound(CLAP) and only plays the second sound (GOODBY)

Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long

Const SND_SYNC = &H0        ' Play synchronously (default).
Const SND_NOSTOP = &H10     ' Do not stop any currently playing sound.
Const SND_NODEFAULT = &H2 '/* silence (!default) if sound not found */
Const SND_MEMORY = &H4 '/* pszSound points to a memory file */
Const SND_LOOP = &H8 '/* loop the sound until next sndPlaySound */

Dim sndData() As Byte



Private Sub Command1_Click()
Chill 3, "CLAP"
Chill 1, "GOODBY"
End Sub

Public Sub Chill(seconds As Integer, SoundName As String)
  seconds = seconds * 1000
    Timer2.Interval = seconds '1000
    Timer2.Enabled = True
     sndData = LoadResData(SoundName, "SOUND")
      sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY
End Sub

Sub Timer2_Timer()
    Timer2.Enabled = False
    sndPlaySound ByVal 0, 0 'stop sound
End Sub
how can this be fixed?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Try
Private Sub Command1_Click()
Chill 3, "CLAP"
DoEvents
Chill 1, "GOODBY"
End Sub

Open in new window

Avatar of isnoend2001

ASKER

Thanks  MartinLiss but no go,
The only way to make it play only the first sound is to comment out the second sound
This works, but Chill 3, "CLAP"
'DoEvents
Sleep 2000
Chill 1, "GOODBY"

This works
but I have no control over how long the first sound plays
Do you use Option Explicit? If not you probably should (everyone should) because you don't have SND_ASYNC defined in the code you show and that may well be the problem.

Const SND_ASYNC = &H1         '  play asynchronously
Yes I use Option Explicit: some how i have 2 different Delarations for playing sound
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long

Const SND_SYNC = &H0        ' Play synchronously (default).
Const SND_NOSTOP = &H10     ' Do not stop any currently playing sound.

Private Declare Function PlaySoundData Lib "winmm.dll" Alias "PlaySoundA" (lpData As Any, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const SND_ASYNC = &H1 ' /* play synchronously (default) */
Const SND_NODEFAULT = &H2 '/* silence (!default) if sound not found */
Const SND_MEMORY = &H4 '/* pszSound points to a memory file */
Const SND_LOOP = &H8 '/* loop the sound until next sndPlaySound */
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess sleep is the only way I was hoping that a do loop until some variable becomes true would work. seems i have done that some time in the past