GordonFreeman Posted August 10, 2012 Share Posted August 10, 2012 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" Frabjous Installation Link to comment Share on other sites More sharing options...
abberration Posted August 10, 2012 Share Posted August 10, 2012 (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 August 10, 2012 by abberration Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
GordonFreeman Posted August 10, 2012 Author Share Posted August 10, 2012 (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 August 11, 2012 by GordonFreeman Frabjous Installation Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now