Solved

Play 2 short sounds in a row vb6

Posted on 2013-11-18
7
350 Views
Last Modified: 2013-11-18
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?
0
Comment
Question by:isnoend2001
  • 4
  • 3
7 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39657879
Try
Private Sub Command1_Click()
Chill 3, "CLAP"
DoEvents
Chill 1, "GOODBY"
End Sub

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39657910
Thanks  MartinLiss but no go,
The only way to make it play only the first sound is to comment out the second sound
0
 

Author Comment

by:isnoend2001
ID: 39657917
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:Martin Liss
ID: 39657948
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
0
 

Author Comment

by:isnoend2001
ID: 39657966
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 */
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39657990
From this line it looks like you are only using sndPlaySound.

 sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY

but if you put those several constants in module and make them Public then it doesn't matter which form you "play" from. For example:
Option Explicit

Public Const SND_ASYNC = &H1         '  play asynchronously

Open in new window

0
 

Author Closing Comment

by:isnoend2001
ID: 39658065
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 121
bit defender blocks good applications 2 105
Passing a Text Box name to a Sub 6 102
TT Auto Dashboard 13 100
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question