YouTip LogoYouTip

Prop Audio Duration

HTML DOM Audio duration Property

HTML DOM Audio duration Property

Example

Get the length of the current audio:

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

x output result:

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 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 Explorer Firefox Opera Google Chrome Safari

All major 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 number value representing the length of the audio in seconds. If the audio is not set, it returns NaN (Not a Number). If the audio stream has no predefined length, it returns "Inf" (Infinity).

Audio Object Reference Audio Object

← Prop Audio EndedProp Audio Defaultplaybackrate β†’