Latest web development tutorials

HTML DOM Audio duration property

Audio Object Reference Audio Object

Examples

Get the current length of the audio:

var x = document.getElementById("myAudio").duration;

x The output is:

1.515102

try it"

Definition and Usage

duration property returns the current length of the audio, in seconds.

Note: Different browsers return a different value. In the example above, and Opera 18+ Chrome returns "1.515102." Firefox returns "1.509298." Internet Explorer Returns "1.5491875." Safari Back "1.5149999856948853." Opera 12 Returns "1.5092970520000002."

Note: This property is read-only.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support duration property.

Note: Internet Explorer 8 and earlier versions of IE does not support this property.


grammar

audioObject .duration

technical details

return value: Numeric value that indicates the length of the audio, in seconds. If you do not set the audio, NaN (not a number) is returned. If the audio stream is no predefined length, returns "Inf" (Infinity: infinite).


Audio Object Reference Audio Object