如何让他在 HTML5 视频的第 5 秒(不包括缓冲区加载时间)出现警报?我尝试使用 currentTime 但无法显示任何内容...
<video id="video1"><source src="url" type="video/mp4" /></video>
提前非常感谢
最佳答案
我认为使用 setInterval
或setTimeout
是一个坏想法,因为用户可以暂停视频,或者视频正在缓冲,...所以这不是执行您正在寻找的操作的准确方式。
除此之外,您还可以使用 timeupdate
事件验证 currentTime
您的视频,如下所示:
$(function(){
var video = $('#video1')[0], current_time = 0, alert_showed = false;
video.addEventListener('timeupdate', function(){
current_time = Math.floor(video.currentTime);
if(current_time == 5 && !alert_showed){
alert_showed = true;
alert('text here : ' + current_time);
}
})
})
您可以看到此代码的工作示例 here .
希望能有所帮助。
关于javascript - HTML5 视频函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28914479/