HTMLMediaElement.duration
The read-only HTMLMediaElement
property duration
indicates the length of the element's media in seconds.
Syntax
myDuration = htmlMediaElement.duration
Value
A double-precision floating-point value indicating the duration of the media in seconds. If no media data is available, the value NaN
is returned. If the element's media doesn't have a known duration—such as for live media streams—the value of duration
is +Infinity
.
Examples
var obj = document.createElement('video'); console.log(obj.duration); // NaN
Specifications
Specification |
---|
HTML Standard (HTML) # dom-media-duration-dev |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
duration |
43 |
12 |
3.5 |
9 |
≤12.1 |
3.1 |
43 |
43 |
4 |
≤12.1 |
3 |
4.0 |
See also
- Web media technologies
-
HTMLMediaElement.currentTime
: The current playback position of the media - The
<audio>
and<video>
elements
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration