有个抖机灵的办法: 不直接调用:backgroundAudioManager.stop()。 而是先调用backgroundAudioManager.seek(0),将播放进度挪到第0秒, 再调用暂停backgroundAudioManager.pause() 这样下次调用播放的时候,音频就能从头开始播放了 亲测有效
getBackgroundAudioManager在调用stop后重新播放无效[代码]voice: [代码][代码]function[代码] [代码](event){[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]clearInterval(that.data.times)[代码][代码] [代码][代码]var[代码] [代码]arr = [[代码][代码]'../../image/voice_001.png'[代码][代码], [代码][代码]'../../image/voice_011.png'[代码][代码],[代码][代码]'../../image/voice_01.png'[代码][代码]][代码][代码] [代码] [代码] [代码][代码]const backgroundAudioManager = wx.getBackgroundAudioManager()[代码][代码] [代码][代码]backgroundAudioManager.stop()[代码][代码] [代码][代码]backgroundAudioManager.onStop([代码][代码]function[代码][代码](){[代码][代码] [代码][代码]clearInterval(that.data.times)[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]bigPic: arr[2][代码][代码] [代码][代码]})[代码][代码] [代码][代码]console.log([代码][代码]"播放停止"[代码][代码]);[代码][代码] [代码][代码]})[代码][代码] [代码][代码]backgroundAudioManager.src = event.target.dataset.url [代码][代码]// 设置了 src 之后会自动播放[代码][代码] [代码][代码]backgroundAudioManager.onPlay([代码][代码]function[代码][代码](){[代码][代码] [代码][代码]console.log([代码][代码]"开始播放"[代码][代码])[代码][代码] [代码][代码]util.play(arr, [代码][代码]"bigPic"[代码][代码], [代码][代码]function[代码] [代码](i, time) {[代码] [代码] [代码][代码]that.setData({[代码][代码] [代码][代码]bigPic: arr[i],[代码][代码] [代码][代码]times: time[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]backgroundAudioManager.onEnded([代码][代码]function[代码][代码](){[代码][代码] [代码][代码]clearInterval(that.data.times)[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]bigPic: arr[2][代码][代码] [代码][代码]}) [代码][代码] [代码][代码]console.log([代码][代码]"播放完成"[代码][代码]);[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码]现在是需要做一个点击把之前的播放停止然后重新播放的功能,现在点击之后停止了,但是重新播放无法生效,想知道有什么办法可以让重新播放生效
12-12