Discussion:
toggling a wav file in vb6 question
(too old to reply)
steve marchant
2004-07-21 17:38:49 UTC
Permalink
I used the following code to start and stop a wav sound. Note the use of
separate buttons to start and stop the sound. I'd appreciate seeing code
which will enable the sound to be toggled on/off by a single button (eg.
Command1). Any suggestions,please?
steve

Const SND_LOOP = &H8
Const SND_ASYNC = &H1
Const SND_PURGE = &H40
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal
lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Private Sub Command1_Click()
PlaySound "C:\windows\media\microsoft office 2000\ricochet.wav", 0,
SND__LOOP Or SND_ASYNC
End Sub

'this procedure stops repeated playsound.
Private Sub Command2_Click()
PlaySound "", 0, SND_PURGE
End Sub
Martin Trump
2004-07-21 18:03:39 UTC
Permalink
Post by steve marchant
I used the following code to start and stop a wav sound. Note the use of
separate buttons to start and stop the sound. I'd appreciate seeing code
which will enable the sound to be toggled on/off by a single button (eg.
Command1). Any suggestions,please?
Try a Static Boolean variable in the click event.
(Untested!)
...

Static Boolplay as Boolean

Boolplay = Not Boolplay
If Boolplay Then
'Play
Else
'Stop
End If

HTH.

Regards
--
Martin Trump
steve marchant
2004-07-21 18:36:58 UTC
Permalink
Post by Martin Trump
Post by steve marchant
I used the following code to start and stop a wav sound. Note the use of
separate buttons to start and stop the sound. I'd appreciate seeing code
which will enable the sound to be toggled on/off by a single button (eg.
Command1). Any suggestions,please?
Try a Static Boolean variable in the click event.
(Untested!)
...
Static Boolplay as Boolean
Boolplay = Not Boolplay
If Boolplay Then
'Play
Else
'Stop
End If
HTH.
Regards
--
Martin Trump
Works fine,Martin. Thanks a lot.
steve

Loading...