Home > Web Front-end > H5 Tutorial > 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)

不言
Release: 2018-08-06 17:49:32
Original
7810 people have browsed it

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>
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template