diff --git a/TUICallKit-Vue3/manifest.json b/TUICallKit-Vue3/manifest.json index 5389584a..642f8e7d 100644 --- a/TUICallKit-Vue3/manifest.json +++ b/TUICallKit-Vue3/manifest.json @@ -57,7 +57,9 @@ "optimization" : { "subPackages" : true }, - "usingComponents" : true + "usingComponents" : true, + /* 节拍器后台播放需要,iOS 必需 */ + "requiredBackgroundModes" : ["audio"] }, "mp-alipay" : { "usingComponents" : true diff --git a/TUICallKit-Vue3/pages.json b/TUICallKit-Vue3/pages.json index 8fe89074..229719a4 100644 --- a/TUICallKit-Vue3/pages.json +++ b/TUICallKit-Vue3/pages.json @@ -122,7 +122,8 @@ "navigationBarBackgroundColor": "#f8fafc", "navigationBarTextStyle": "black", "backgroundColor": "#f8fafc", - "disableScroll": true + "disableScroll": true, + "requiredBackgroundModes": ["audio"] } } ] diff --git a/TUICallKit-Vue3/training/pages/metronome.vue b/TUICallKit-Vue3/training/pages/metronome.vue index 023797ee..3f8bda59 100644 --- a/TUICallKit-Vue3/training/pages/metronome.vue +++ b/TUICallKit-Vue3/training/pages/metronome.vue @@ -244,14 +244,21 @@ onShow(() => { preload() }) +/** + * onHide 故意不 stop: + * - 切到后台 / 微信"小窗" 都会触发 onHide + * - 配合 pages.json 的 requiredBackgroundModes:["audio"], + * 小程序退到后台后节拍声仍然可以继续(健走时把手机放兜里也能听到响) + * - 真正离开节拍器页(navigateBack/重启) 会 onUnload+onUnmounted, + * 在那里清理屏幕常亮 + */ onHide(() => { - if (isPlaying.value) { - stop() - uni.setKeepScreenOn({ keepScreenOn: false }) - } + /* 不再主动 stop, 让节拍器在后台继续工作 */ }) onUnmounted(() => { + /* 页面卸载才真正停 + 释放屏幕常亮 */ + if (isPlaying.value) stop() uni.setKeepScreenOn({ keepScreenOn: false }) })