asseto Posted June 17, 2012 Share Posted June 17, 2012 Hi! I want to create button in script and play sound when this button is pressed? I saw one script where it is implemented, but it's too difficult. Can someone give some instructions? I tried soundplay, but it plays file only when script is closed, it's not what I want. Thanks! Link to comment Share on other sites More sharing options...
Venix Posted June 17, 2012 Share Posted June 17, 2012 (edited) Does this work for you? #include <Sound.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 181, 85, 192, 124) $Play = GUICtrlCreateButton("Play", 8, 8, 161, 33) $Stop = GUICtrlCreateButton("Stop", 7, 43, 161, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Play $Sound = _SoundOpen(@WindowsDir & "mediatada.wav") ; Replace this directory with the directory of your sound. _SoundPlay($Sound) ; This will play the sound that you called as a variable earlier. Case $Stop _SoundStop($Sound) ; Stop the sound if it is currently playing. _SoundClose($Sound) ; Close the sound that you opened earlier. EndSwitch WEnd Edit: Woops apparently my includes got cut off somehow edited the code and should work now. Edited June 17, 2012 by Venix Link to comment Share on other sites More sharing options...
asseto Posted June 18, 2012 Author Share Posted June 18, 2012 Wow, thank you! That's exactly what I need! I'll try this later today and will post results Link to comment Share on other sites More sharing options...
asseto Posted June 19, 2012 Author Share Posted June 19, 2012 It works! 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