fix
This commit is contained in:
@@ -87,18 +87,14 @@ Page({
|
||||
if (wx.setVisualEffectOnCapture) wx.setVisualEffectOnCapture({ visualEffect: 'none' });
|
||||
|
||||
if (this.data.currentTime > 0) {
|
||||
wx.setStorageSync("interruptedTime", this.data.currentTime);
|
||||
this.flushProgress();
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
//@ts-ignore
|
||||
if (wx.setVisualEffectOnCapture) wx.setVisualEffectOnCapture({ visualEffect: 'none' });
|
||||
|
||||
if (this.data.currentTime > 0) {
|
||||
wx.setStorageSync("interruptedTime", this.data.currentTime);
|
||||
wx.setStorageSync("currentTime", this.data.currentTime);
|
||||
}
|
||||
this.flushProgress();
|
||||
|
||||
try {
|
||||
this.pauseVideoBeforeNavigate();
|
||||
@@ -130,6 +126,8 @@ Page({
|
||||
wx.onNetworkStatusChange(this._networkStatusChangeHandler);
|
||||
|
||||
this._pauseVideoHandler = () => {
|
||||
// 来电等系统中断:先落盘进度再暂停
|
||||
this.flushProgress();
|
||||
this._wasPlayingBeforeInterrupt = this.data.playing;
|
||||
this.pauseVideoBeforeNavigate();
|
||||
};
|
||||
@@ -143,6 +141,7 @@ Page({
|
||||
};
|
||||
|
||||
this._appHideHandler = () => {
|
||||
this.flushProgress();
|
||||
this.setData({ isAppHidden: true });
|
||||
this.pauseVideoBeforeNavigate();
|
||||
};
|
||||
@@ -172,25 +171,36 @@ Page({
|
||||
this.getVideoContext().play();
|
||||
},
|
||||
|
||||
syncResumeTime() {
|
||||
if (this.data.resumeTime > 0) {
|
||||
this.getVideoContext().seek(this.data.resumeTime);
|
||||
// 统一写进度:interruptedTime 与 currentTime 成对写,保证两者永远一致
|
||||
flushProgress(time?: number) {
|
||||
const t = Math.max(time || this.data.currentTime || 0, Number(wx.getStorageSync("currentTime") || 0));
|
||||
if (t <= 0) return;
|
||||
wx.setStorageSync("interruptedTime", t);
|
||||
wx.setStorageSync("currentTime", t);
|
||||
},
|
||||
|
||||
// 视频元信息就绪后才 seek,否则 seek 会被静默忽略
|
||||
onPlayerLoadedMetadata() {
|
||||
this.seekToResumeTime();
|
||||
},
|
||||
|
||||
seekToResumeTime() {
|
||||
const t = this.getResumeTime();
|
||||
if (t > 0) {
|
||||
this.getVideoContext().seek(t);
|
||||
}
|
||||
},
|
||||
|
||||
onPlayerPlay() {
|
||||
this.setData({ playing: true, resumeTime: 0 });
|
||||
wx.removeStorageSync("interruptedTime");
|
||||
this.setData({ playing: true });
|
||||
this.seekToResumeTime();
|
||||
this.startSendProgress();
|
||||
},
|
||||
|
||||
onPlayerPause() {
|
||||
this.setData({ playing: false });
|
||||
this.clearSendProgressTimer();
|
||||
// 用户主动点击暂停时,存入进度
|
||||
if (this.data.currentTime > 0) {
|
||||
wx.setStorageSync("interruptedTime", this.data.currentTime);
|
||||
}
|
||||
this.flushProgress();
|
||||
},
|
||||
|
||||
onPlayerEnded() {
|
||||
@@ -212,16 +222,12 @@ Page({
|
||||
|
||||
// 接收原生组件的时间更新
|
||||
onPlayerTimeUpdate(e: any) {
|
||||
// 兼容 VOD 插件可能多包一层 detail 的情况
|
||||
let time = e.detail?.currentTime ?? e.detail?.detail?.currentTime;
|
||||
if (typeof time === 'number' && time > 0) {
|
||||
const currentTime = Math.floor(time);
|
||||
this.data.currentTime = currentTime; // 纯内存更新,不触发无用渲染
|
||||
|
||||
// 每 5 秒落盘一次 currentTime 作为终极兜底,不要太频繁避免卡顿
|
||||
if (currentTime % 5 === 0) {
|
||||
wx.setStorageSync("currentTime", currentTime);
|
||||
}
|
||||
if (currentTime === this.data.currentTime) return;
|
||||
this.data.currentTime = currentTime;
|
||||
if (currentTime % 5 === 0) this.flushProgress(currentTime);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -305,9 +311,9 @@ Page({
|
||||
eveId: targetData.eveId,
|
||||
nodes: htmlToWxNodes(targetData.content),
|
||||
fileid: targetData.extend.fileid,
|
||||
resumeTime: this.getResumeTime(),
|
||||
});
|
||||
|
||||
this.syncResumeTime();
|
||||
this.selectComponent("#tabs")?.resize();
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user