Audio duration Property
Example
Get the length of an audio:
var x = document.getElementById("myAudio").duration;
The result of x could be:
1.515102
Try it yourself »
Definition and Usage
The duration property returns the length of an audio, in seconds.
Note: Different browsers return different values. In the example above, Opera 18+ and Chrome returns "1.515102". Firefox returns "1.509298". Internet Explorer returns "1.5491875". Safari returns "1.5149999856948853", while Opera 12 returns "1.5092970520000002".
Note: This property is read-only.
Browser Support
The duration property is supported in all major browsers.
Note: This property is not supported in Internet Explorer 8 and earlier versions.
Syntax
audioObject.duration
Technical Details
Return Value: | A Number, representing the length of the audio, in seconds. If no audio is set, "NaN" (Not-a-Number) is returned. If the audio is streamed and has no predefined length, "Inf" (Infinity) is returned. |
---|
Audio Object