Function Reference


Play a sound file

#include <Sound.au3>
_SoundPlay ( $aSndID [, $iWait = 0] )


$aSndID Sound ID array as returned by _SoundOpen() or a file name
$iWait [optional] This flag determines if the script should wait for the sound to finish before continuing:
    0 = continue script while sound is playing (default)
    1 = wait until sound has finished

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 = Play Failed
2 = $iWait parameter is invalid
3 = Invalid Sound ID. Use return array from _SoundOpen() or a valid file name.


In Windows Vista or later, "\Windows\Media\..." files containing spaces must be opened with _SoundOpen() before using this command with the returned Sound ID array.


_SoundOpen, _SoundPause, _SoundResume, _SoundSeek, _SoundStop


#include <MsgBoxConstants.au3>
#include <Sound.au3>

Local $aSound = _SoundOpen(@WindowsDir & "\media\tada.wav")
If @error = 2 Then
    MsgBox($MB_SYSTEMMODAL, "Error", "The file does not exist")
ElseIf @extended <> 0 Then
    Local $iExtended = @extended ; Assign because @extended will be set after DllStructCreate().
    Local $tText = DllStructCreate("char[128]")
    DllCall("winmm.dll", "short", "mciGetErrorStringA", "str", $iExtended, "struct*", $tText, "int", 128)
    MsgBox($MB_SYSTEMMODAL, "Error", "The open failed." & @CRLF & "Error Number: " & $iExtended & @CRLF & "Error Description: " & DllStructGetData($tText, 1) & @CRLF & "Please Note: The sound may still play correctly.")
    MsgBox($MB_SYSTEMMODAL, "Success", "The file opened successfully")

_SoundPlay($aSound, 1)