Jump to content
Sign in to follow this  

Playing sound file when pressing button

Recommended Posts



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.


Share this post

Link to post
Share on other sites

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)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
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.

Edit: Woops apparently my includes got cut off somehow edited the code and should work now.

Edited by Venix

Share this post

Link to post
Share on other sites

Wow, thank you! That's exactly what I need! I'll try this later today and will post results ;)

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.