English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The duration attribute gives the length of the media in seconds. If no media data is available, it is zero.
HTML Audio/Video DOM Reference Manual
Get the current video length:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML Audio/video duration attribute usage-Basic Tutorial(oldtoolbag.com)</title> </head> <body> <button onclick="getVidDur()" type="button">Get the current video length: </button> <br> <video id="video1" controls="controls"> <source src="mov_bbb.mp4" type="video/mp4"> <source src="mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video tag. </video> <script> myVid=document.getElementById("video1"); function getVidDur() { alert(myVid.duration); } </script> </body> </html>Test to see ‹/›
The duration property returns the current audio/The length of the video, in seconds.
If the audio is not set/If the length of the video is not set, it returns NaN (Not a Number).
Note: This property is read-only.
IEFirefoxOperaChromeSafari
All major browsers support the duration property.
Note:Internet Explorer 8 and earlier versions do not support this property.
audio|video.duration
Return value: | Numeric value representing the audio/The length of the video, in seconds. |
---|