HTMLMediaElement.duration

The HTMLMediaElement.duration property gives the length of the media in seconds, or zero if no media data is available.

Syntax

var myDuration = audioOrVideo.duration

Value

A double. If the media data is available but the length is unknown, this value is NaN. If the media is streamed and has no predefined length, the value is Inf.

Example

var obj = document.createElement('video');
console.log(obj.duration); // NaN

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'HTMLMediaElement.duration' in that specification.
Living Standard  
HTML5
The definition of 'HTMLMediaElement.duration' in that specification.
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

See also

Document Tags and Contributors

Contributors to this page: sideshowbarker, fscholz, erikadoyle, markg
Last updated by: sideshowbarker,