Jump to content

Button and a Sound


Recommended Posts

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"

Link to comment
Share on other sites

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
Link to comment
Share on other sites

#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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...