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
//
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("211111111111111111");
_this.last30sTimer = false;
@ -433,22 +435,36 @@ 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() {
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);
if (_this.record > 0.1) {
_this.current_sign = _this.record;
document.getElementById("video").addEventListener("play", plays, false);
} else {
// vd.play();
//
if (_this.video_timer) {
clearInterval(_this.video_timer);
}
_this.video_timer = setInterval(timer, 100);
}
//
@ -856,6 +872,8 @@ export default {
},
beforeRouteLeave(to, from, next) {
//
// console.log(":", this.video_timer);
if (this.video_timer) {
clearInterval(this.video_timer);
this.video_timer = null; //