从微信客户端6.7.2版本开始,若需要在小程序切后台后继续播放音频,需要在 app.json 中配置 [代码]requiredBackgroundModes[代码] 属性。开发版和体验版上可以直接生效,正式版还需通过审核。
getBackgroundAudioManager ios 没有声音?const backgroundAudioManager = wx.getBackgroundAudioManager(); play(e){ this.backmusic() let id = e.currentTarget.dataset.id; let src = e.currentTarget.dataset.src; this.audioCtx = wx.createAudioContext(e.currentTarget.dataset.name) if(this.data.nowid == id && this.data.nowflog == true){ backgroundAudioManager.pause() this.setData({ nowflog:false, nowid:null, }) }else if(this.data.nowid != id){ if(this.data.nowname != null){ this.audioCtx1 = wx.createAudioContext(this.data.nowname); backgroundAudioManager.pause() } console.log(this.audioCtx); backgroundAudioManager.title = e.currentTarget.dataset.name backgroundAudioManager.src = src this.setData({ nowid:id, nowurl:src, nowname:e.currentTarget.dataset.name, nowflog:true }) } }, app.json 已经配置
2022-01-25