Function Reference


_SoundLength

Returns the length of the soundfile.

#include <Sound.au3>
_SoundLength($aSnd_id [, $iMode])

Parameters

$aSnd_id Sound ID array as returned by _SoundOpen() or a file name
$iMode [optional] This flag determines the format of the returned sound length
1 = hh:mm:ss where h = hours, m = minutes and s = seconds
2 = milliseconds

Return Value

Success: Sound Length
Failure: 0 and set @error
@error: 1 = $iMode is invalid
3 = Invalid Sound ID. Use return array from _SoundOpen() or valid file name.

Remarks

This function will return the best available value for the length of the file regardless of encoding method or parameter type.

Related

_SoundPos, _SoundOpen

Example


#include <Sound.au3>

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

MsgBox(0, "Sound Length", "The Sound has a length of:" & @CRLF & "hh:mm:ss - " & _
        _SoundLength($aSound, 1) & @CRLF & "Milliseconds - " & _SoundLength($aSound, 2))