Jump to content

Recommended Posts

Posted

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!

Posted (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 by Venix

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
×
×
  • Create New...