Stop the music !

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Thanks to the forum I can start any wavfile now in my db-solution.
My question is, how do I make it possible for user to stop the music when
user wants to.

My situation:
I have a module called "basPlaySound":

Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
(ByVal filename As String, ByVal snd_async As Long) As Long

Function PlayStuff(sWavFile As String)
End Function

Function StopStuff(sWavFile As String)
End Function

and two eventprocedures:
Private Sub cmdPlay_Click()
Call PlayStuff (sound.wav)
End Sub

Private Sub cmdStop_Click()
Call StopStuff (sound.wav)
End Sub

Now the cmdPlay procedure works great, but the cmdStop procedure doesn't
work at all (not even an error).
Can anyone please help me on this ?

Thank you in advance !
Greetings
 
Care to share the code in your PlayStuff and StopStuff functions?

I'm assuming that PlayStuff includes a line of code like:

lngRet = apisndPlaySound(sWaveFile, 8)

(although the number can vary)

To make the sound stop, you'd need something like:

lngRet = apisndPlaySound(0, 1)
 
Hi Douglas,
Thank you for responding

1. the PlayStuff functioncode you asked for, is the one I gave you, and it
works !!

Function PlayStuff(sWavFile As String)
End Function

No apisndPlaySound - code needed !

2. But for the StopStuff - code to work succesfully I had to use your
code-idea:

Function StopStuff(sWavFile As String)
Dim lngRet As Long
lngRet = apisndPlaySound(0, 1)
StopStuff = lngRet
End Function

So, thank you for that !

There's one more question on this: When clicking the Stop-button the music
stops but I hear a beep.
Can you tell me how I can get rid of the beep ?

Thank you in advance !

Greetings
 
Sorry, but there's no conceivable way that a function that consists solely
of

Function PlayStuff(sWavFile As String)
End Function

can cause your WAV file to play! Someplace you must have another definition
for PlayStuff that's being used. Try single-stepping through your
cmdPlay_Click event and see where it takes you. Until we can determine why
your file is playing, it'll be difficult to fix your beeping issue.
 
1. PlayStuff
I can't recall precisely what caused the skinny PlayStuff function I gave
you to play the music earlier on. Because now it turns out that the only way
the Play- and Stop-events work, is with the code you gave me:

Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
(ByVal filename As String, ByVal snd_async As Long) As Long

Function PlayStuff(sWavFile As String)
Dim lngRet As Long
lngRet = apisndPlaySound(sWavFile, 1)
PlayStuff = lngRet
End Function

Function StopStuff(sWavFile As String)
Dim lngRet As Long
lngRet = apisndPlaySound(0, 1)
StopStuff = lngRet
End Function

There's no other Play-code in the project

2.Beep
Single-stepping through the events, the Beep occurs only in the
StopStuff-code when stepping from lngRet = apisndPlaySound(0, 1) to
StopStuff = lngRet

I hope this is the information you need to help me further on this ?
 
Hi Douglas,
To solve the problem for this moment I created a wavefile called
"silence.wav" and have it run with the PlayStuff function. I admit that it's
not a "real" VB-solution, but it serves me for this moment.

Thank you very much for helping me and encouraging me again on this thread !!

Greetings
 
Back
Top