视频HTML5的函数

function for a video HTML5

本文关键字:函数 HTML5 视频      更新时间:2023-09-26

如何让他在视频HTML5的第5秒出现警觉,不包括缓冲区加载时间?我尝试使用当前时间,但我无法显示任何内容...

<video id="video1"><source src="url" type="video/mp4" /></video>

提前非常感谢

我认为使用setIntervalsetTimeout是一个主意,因为例如,用户可以暂停视频,或者如果视频正在缓冲,...因此,做您正在寻找的事情并不准确。

相反,您可以使用 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);
        }
    })
})

您可以在此处查看此代码的工作示例。

希望能有所帮助。