Solved

Play 2 short sounds in a row vb6

Posted on 2013-11-18
7
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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