diff --git a/miniprogram/app.json b/miniprogram/app.json index 3565e82..25cfe4e 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -2,7 +2,6 @@ "pages": [ "pages/tab-bar/medicine-box/index", "pages/tab-bar/medicine-box/add/index", - "pages/tab-bar/drug-wiki/index", "pages/tab-bar/education/index", "pages/tab-bar/profile/index", "pages/tab-bar/profile/edit/index", @@ -27,10 +26,6 @@ "pagePath": "pages/tab-bar/medicine-box/index", "text": "电子药箱" }, - { - "pagePath": "pages/tab-bar/drug-wiki/index", - "text": "药品百科" - }, { "pagePath": "pages/tab-bar/education/index", "text": "惠教中心" diff --git a/miniprogram/custom-tab-bar/index.ts b/miniprogram/custom-tab-bar/index.ts index 7001f33..c484449 100644 --- a/miniprogram/custom-tab-bar/index.ts +++ b/miniprogram/custom-tab-bar/index.ts @@ -7,11 +7,6 @@ Component({ text: '电子药箱', icon: '💊', }, - { - pagePath: 'pages/tab-bar/drug-wiki/index', - text: '药品百科', - icon: '📖', - }, { pagePath: 'pages/tab-bar/education/index', text: '惠教中心', diff --git a/miniprogram/pages/live/video/video.ts b/miniprogram/pages/live/video/video.ts index ff4e6f3..27cf9ab 100644 --- a/miniprogram/pages/live/video/video.ts +++ b/miniprogram/pages/live/video/video.ts @@ -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(); }, diff --git a/miniprogram/pages/live/video/video.wxml b/miniprogram/pages/live/video/video.wxml index ddda9af..41d84e4 100644 --- a/miniprogram/pages/live/video/video.wxml +++ b/miniprogram/pages/live/video/video.wxml @@ -15,13 +15,15 @@ height="210px" appid="1304584727" fileid="{{fileid}}" + initial-time="{{resumeTime}}" enable-progress-gesture="{{false}}" playerid="myPlayerId" bindplay="onPlayerPlay" bindpause="onPlayerPause" bindended="onPlayerEnded" binderror="onPlayerError" - bindtimeupdate="onPlayerTimeUpdate" + bindtimeupdate="onPlayerTimeUpdate" + bindloadedmetadata="onPlayerLoadedMetadata" show-fullscreen-btn >