Audio durationProperty
Examples
Get the length of the current audio:
var x = document.getElementById("myAudio").duration;
xThe output result is:
1.515102
Try it yourself »
Definition and Usage
The duration property returns the length of the current audio, in seconds.
Note:Different browsers return different values. In the above example, Opera 18+ and Chrome return "1.515102". Firefox returns "1.509298". Internet Explorer returns "1.5491875". Safari returns "1.5149999856948853". Opera 12 returns "1.5092970520000002".
Note:This property is read-only.
Browser Support
![]()
![]()
![]()
![]()
![]()
All mainstream browsers support the duration property.
Note:Internet Explorer 8 and earlier IE versions do not support this property.
Syntax
audioObject.duration
Technical Details
| Return value: | A numeric value representing the length of the audio, in seconds. If no audio is set, it returns NaN (Not a Number). If the audio stream has no predefined length, it returns "Inf" (Infinity: infinite). |
|---|
Audio Object Other extensions