<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取播放器播放时间和停止播放</title>
<script src="./static/js/jquery3.5.0.min.js"></script>
</head>
<body>
<video id="Video" width="100%" height="100%" controls="controls">
<source src="./static/video/1.mp4" type="video/mp4" style="margin-top: 0px;">
<source src="./static/video/1.mp4" type="video/ogg">
</video>
<script type="text/javascript">
// 获取id="video"的video元素
v = document.getElementById("Video");
//控制当前播放位置
v.currentTime=20;
// 在当前播放位置改变时执行该方法:
v.ontimeupdate = function () {
var currenttime = v.currentTime;
var alltime = v.duration;
console.log("播放视频中");
if (currenttime >= 30) {
//视频暂停
v.pause();
console.log("播放了:" + currenttime + "s");
console.log("总共:" + alltime + "s");
console.log("播放比例:" + currenttime / alltime + "%");
alert("免费观看结束,请充值会员观看");
return false;
}
};
</script>
</body>
</html>
本文地址:https://blog.csdn.net/qq_35416214/article/details/107288067