Solved

Play 2 short sounds in a row vb6

Posted on 2013-11-18
7
344 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 45

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 45

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 45

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now