fix(study): 修复视频播放结束逻辑和定时器清理问题
修复视频播放结束判断条件,增加对播放进度的验证 添加定时器清理逻辑防止内存泄漏
This commit is contained in:
parent
2704846056
commit
07a5f956f2
@ -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("最后2秒我运行了11111111111111111");
|
// console.log("最后2秒我运行了11111111111111111");
|
||||||
_this.last30sTimer = false;
|
_this.last30sTimer = false;
|
||||||
@ -433,22 +435,36 @@ 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() {
|
||||||
|
const duration = document.getElementById("video").duration;
|
||||||
|
// console.log(duration, "视频播放完啦,真的吗?");
|
||||||
|
|
||||||
|
if (_this.current_sign >= duration - 10) {
|
||||||
document
|
document
|
||||||
.getElementById("video")
|
.getElementById("video")
|
||||||
.removeEventListener("ended", onPlayerEnded, false);
|
.removeEventListener("ended", onPlayerEnded, false);
|
||||||
_this.onPlayerEnded();
|
_this.onPlayerEnded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
console.log("视频播放进度:", _this.record);
|
console.log("视频播放进度:", _this.record);
|
||||||
if (_this.record > 0.1) {
|
if (_this.record > 0.1) {
|
||||||
_this.current_sign = _this.record;
|
_this.current_sign = _this.record;
|
||||||
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; // 重置定时器变量
|
||||||
|
Loading…
x
Reference in New Issue
Block a user