Latest web development tutorials

HTML Audio / Video DOM duration property

HTML audio / video Tag Reference HTML Audio / Video DOM Reference

Examples

Get the current length of the video:

myVid=document.getElementById("video1");
alert(myVid.duration);

try it"

Definition and Usage

duration property returns the current length of the audio / video in seconds.

If no audio / video, return NaN (Not-a-Number).


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support duration property.

Note: 8 and earlier versions of Internet Explorer does not support this property.


grammar

audio|video .duration

technical details

返回值: 数字值,表示音频/视频的长度,以秒计。


HTML audio / video Tag Reference HTML Audio / Video DOM Reference