From a42fe477303591281b9865c72b28733f146866ba Mon Sep 17 00:00:00 2001 From: xwenliang Date: Mon, 5 Dec 2022 11:42:15 +0800 Subject: [PATCH] feat: reset audio when destroy list --- README.md | 4 ++-- pages/result/result.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d58cad7..e5968db 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - [x] 内容安全问题处理 - https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html -- [ ] 从列表页返回后应该关闭正在播放的列表页语音 +- [x] 从列表页返回后应该关闭正在播放的列表页语音 -- [ ] 时间长了本地缓存文件失效后应当清除对应播放列表 +- [x] 时间长了本地缓存文件失效后应当清除对应播放列表 diff --git a/pages/result/result.js b/pages/result/result.js index 5cee587..aabb334 100644 --- a/pages/result/result.js +++ b/pages/result/result.js @@ -18,15 +18,18 @@ Page({ data: { audioList: formateDate(app.globalData.getAudioList()) }, - onLoad (options) { + onLoad(options){ this.setData({ audioList: formateDate(app.globalData.getAudioList()) }); }, + onUnload(){ + this.resetAudio(); + }, play(e){ const { path } = e.target.dataset; const target = app.globalData.getAudioList().find(v => v.path === path); - audio && audio.destroy(); + this.resetAudio(); audio = wx.createInnerAudioContext({useWebAudioImplement: true}); audio.autoplay = true; audio.src = target.path; @@ -71,5 +74,11 @@ Page({ }); } }); + }, + resetAudio(){ + if(audio){ + audio.destroy(); + audio = null; + } } }); \ No newline at end of file -- libgit2 0.22.2