THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Audio duration Property

Audio Object Reference Audio Object

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

Property
duration Yes Yes Yes Yes Yes

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 Reference Audio Object