Home >Web Front-end >H5 Tutorial >How to implement real-time monitoring of the current playback time in html5 video (code)
This article introduces to you how to realize real-time monitoring of the current playback time (code) of html5 video. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
html:
<video id="video" controls autoplay="autoplay" muted> <source src="" type="video/mp4" /> Your browser does not support the video tag. </video>
js:
//监听播放时间 var video = document.getElementById('video'); //使用事件监听方式捕捉事件 video.addEventListener("timeupdate",function(){ var timeDisplay; //用秒数来显示当前播放进度 timeDisplay = Math.floor(video.currentTime); console.log(Math.floor(video.currentTime)) //当视频播放到 4s的时候做处理 if(timeDisplay == 4){ //处理代码 } },false);
Recommended related articles:
Analysis of audio (audio) in html5
Analysis of video (video) element in html5
The above is the detailed content of How to implement real-time monitoring of the current playback time in html5 video (code). For more information, please follow other related articles on the PHP Chinese website!