fix(study): 修复视频播放结束逻辑和定时器清理问题

修复视频播放结束判断条件,增加对播放进度的验证
添加定时器清理逻辑防止内存泄漏
This commit is contained in:
yindongqi 2025-08-15 15:52:41 +08:00
parent 2704846056
commit 07a5f956f2

View File

@ -413,7 +413,9 @@ export default {
//2s //2s
// //
let duration = document.getElementById("video").duration; 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) { if (_this.last30sTimer && _this.section[_this.choose_section_index].is_end != 1) {
// console.log("211111111111111111"); // console.log("211111111111111111");
_this.last30sTimer = false; _this.last30sTimer = false;
@ -433,14 +435,24 @@ export default {
_this.current_sign = _this.record; _this.current_sign = _this.record;
Toast("从上次记录的地方开始播放"); Toast("从上次记录的地方开始播放");
setTimeout(function () { setTimeout(function () {
//
if (_this.video_timer) {
clearInterval(_this.video_timer);
}
_this.video_timer = setInterval(timer, 100); _this.video_timer = setInterval(timer, 100);
}, 1000); }, 1000);
} }
function onPlayerEnded() { function onPlayerEnded() {
document const duration = document.getElementById("video").duration;
.getElementById("video") // console.log(duration, "");
.removeEventListener("ended", onPlayerEnded, false);
_this.onPlayerEnded(); if (_this.current_sign >= duration - 10) {
document
.getElementById("video")
.removeEventListener("ended", onPlayerEnded, false);
_this.onPlayerEnded();
}
} }
console.log("视频播放进度:", _this.record); console.log("视频播放进度:", _this.record);
@ -449,6 +461,10 @@ export default {
document.getElementById("video").addEventListener("play", plays, false); document.getElementById("video").addEventListener("play", plays, false);
} else { } else {
// vd.play(); // vd.play();
//
if (_this.video_timer) {
clearInterval(_this.video_timer);
}
_this.video_timer = setInterval(timer, 100); _this.video_timer = setInterval(timer, 100);
} }
// //
@ -856,6 +872,8 @@ export default {
}, },
beforeRouteLeave(to, from, next) { beforeRouteLeave(to, from, next) {
// //
// console.log(":", this.video_timer);
if (this.video_timer) { if (this.video_timer) {
clearInterval(this.video_timer); clearInterval(this.video_timer);
this.video_timer = null; // this.video_timer = null; //