diff --git a/src/components/study/courseDetail.vue b/src/components/study/courseDetail.vue index b9c122b..e25bdd6 100644 --- a/src/components/study/courseDetail.vue +++ b/src/components/study/courseDetail.vue @@ -427,7 +427,9 @@ export default { //最后2s调用结束接口 // 获取视频总时长 let duration = document.getElementById("video").duration; - if (curTime >= (duration - 2)) { + // console.log(curTime, _this.current_sign, duration, "-----") + if (curTime >= (duration - 2) && _this.current_sign >= (duration - 10)) { + if (_this.last30sTimer && _this.section[_this.choose_section_index].is_end != 1) { // console.log("最后2秒我运行了11111111111111111"); _this.last30sTimer = false; @@ -447,14 +449,24 @@ export default { _this.current_sign = _this.record; Toast("从上次记录的地方开始播放"); setTimeout(function () { + // 先清除旧定时器 + if (_this.video_timer) { + clearInterval(_this.video_timer); + } _this.video_timer = setInterval(timer, 100); }, 1000); } function onPlayerEnded() { - document - .getElementById("video") - .removeEventListener("ended", onPlayerEnded, false); - _this.onPlayerEnded(); + const duration = document.getElementById("video").duration; + // console.log(duration, "视频播放完啦,真的吗?"); + + if (_this.current_sign >= duration - 10) { + document + .getElementById("video") + .removeEventListener("ended", onPlayerEnded, false); + _this.onPlayerEnded(); + } + } console.log("视频播放进度:", _this.record); @@ -463,6 +475,10 @@ export default { document.getElementById("video").addEventListener("play", plays, false); } else { // vd.play(); + // 先清除旧定时器 + if (_this.video_timer) { + clearInterval(_this.video_timer); + } _this.video_timer = setInterval(timer, 100); } // 监听视频播放完成 @@ -870,6 +886,8 @@ export default { }, beforeRouteLeave(to, from, next) { // 确保离开路由时清除定时器 + // console.log("离开路由时清除定时器:", this.video_timer); + if (this.video_timer) { clearInterval(this.video_timer); this.video_timer = null; // 重置定时器变量