Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Play 2 short sounds in a row vb6

Posted on 2013-11-18
7
Medium Priority
?
363 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 49

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 49

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 49

Accepted Solution

by:
Martin Liss earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses

824 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