Home  >  Article  >  Web Front-end  >  How to implement real-time monitoring of the current playback time in html5 video (code)

How to implement real-time monitoring of the current playback time in html5 video (code)

不言
不言Original
2018-08-06 17:49:327712browse

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(&#39;video&#39;);
//使用事件监听方式捕捉事件
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn