1、獲取視頻時間長度
當視頻載入video后,使用 onloadedmetadata 事件獲取視頻的時間長度。
代碼如下:
video.onloadedmetadata = function () {
var vlength = video.duration;
console.log(vlength);
}
2、當前視頻的播放進度
當視頻開始播放時,可以使用 ontimeupdate 事件獲取視頻當前播放的進度。當video對象的 currenttime 屬性發(fā)生改變時觸發(fā) ontimeupdate 事件。currenttime 屬性是浮點小數(shù),可取到 12 位數(shù)的小數(shù)位數(shù)。
代碼如下:
video.ontimeupdate = function () {
var vtime = video.currenttime;
console.log(vtime);
};
更多信息請查看IT技術專欄