Sign in to follow this  
Followers 0
GordonFreeman

Button and a Sound

3 posts in this topic

I need to stop the sound button, play again to increase the efficiency of the button

Because the logic, the script expects to play the sound and then you can click the button again. What decreases the efficiency of the button

"Calling SoundPlay("") can be used to stop a currently playing sound"

how can I use? "If the sound is playing then stop, and run the function again"

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I wrote an example. While the sound is playing, if you press the button again, the sound will stop.

#include <GUIConstants.au3>
#include <GuiButton.au3>

$Form1 = GUICreate("Play a sound", 128, 66)
$Button1 = GUICtrlCreateButton("Play", 24, 16, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
PlayASound()
EndSwitch
WEnd

Func PlayASound()
$read = _GUICtrlButton_GetText($Button1)
If $read = "Play" Then
SoundPlay(@WindowsDir & "mediatada.wav", 0) ; the 0 tells the script to keep running while sound is playing
GUICtrlSetData($Button1, "Stop")
Else
SoundPlay("") ; leaving a blank entry stops the sound
GUICtrlSetData($Button1, "Play")
EndIf
EndFunc
Edited by abberration

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <GUIConstants.au3>
#include <GuiButton.au3>

Global $VAR = 0
$Form1 = GUICreate("Play a sound", 128, 66)
$Button1 = GUICtrlCreateButton("Play", 24, 16, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If $VAR = 0 Then
PlayASound()
Else
SoundPlay("") ; leaving a blank entry stops the sound
PlayASound()
EndIf
EndSwitch
WEnd

Func PlayASound()
$VAR = 1
SoundPlay(@WindowsDir & "mediatada.wav", 0) ; the 0 tells the script to keep running while sound is playing
$VAR = 0
EndFunc

Ty man

Lol. I'm drugged. hahaha. I only used Soundplay to "0" and got what I wanted

Tyyy

Edited by GordonFreeman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0