Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Audio duration attribute

Audio duration attribute

Audio Object Reference Audio object

Example

Get the length of the current audio:

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

x The output is:

1.515102

Try it »


Definition and Usage

The duration attribute returns the length of the current audio, in seconds.

Note: Different browsers return different values. In the example above, 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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the duration attribute.

Note: Internet Explorer 8 and earlier IE versions do not support this attribute.


Syntax

audioObject

.duration

Technical Details

Return Value: Numeric value representing the length of the audio in seconds. If no audio is set, returns NaN (not a number). If the audio stream has no predefined length, returns "Inf" (Infinity).

Audio Object Reference Audio object