Audio duration attribute
Definition and Usage
duration
The property returns the length of the audio, in seconds.
Different browsers return different values. In the following 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.
Example
Get the length of the audio:
var x = document.getElementById("myAudio").duration;
Syntax
audioObject.duration
Technical Details
Return value: |
A number representing the length of the audio in seconds. If the audio is not set, it returns NaN" (Not-a-Number). If the audio is streamed and does not have a predefined length, it returns "Inf" (Infinity). |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |