<video id="myVideo" controls="controls">
<source type="video/mp4" src="mi.mp4">
</video>
<script>
function videoInit(){
let elevideo = document.getElementById('myVideo');
elevideo.addEventListener('loadedmetadata', () => {
//视频的总长度
console.log('总长度:' + elevideo.duration);
clearInterval(this.timer);
});
elevideo.addEventListener('play', () => {
//播放开始执行的函数
console.log('开始播放');
});
elevideo.addEventListener('playing', () => {
//播放中
console.log('播放中');
this.timer = setInterval(() => {
console.log('播放进度:' + parseFloat(elevideo.currentTime));
}, 100);
});
elevideo.addEventListener(
'ended',
() => {
//结束
console.log('播放结束');
clearInterval(this.timer);
},
false
);
};
// 禁止快进
var sym;
var video = document.querySelector("myVideo")
setInterval(function () {
var time = video.currentTime
if (time - sym > 1) {
video.currentTime = sym
}
sym = video.currentTime
}, 500);
</script>
其它参考
https://www.cnblogs.com/xxflz/p/10160879.html
https://blog.csdn.net/weixin_49577940/article/details/119251184
https://segmentfault.com/q/1010000002740363?_ea=195739