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( "播放完成" ); }) } |
现在是需要做一个点击把之前的播放停止然后重新播放的功能,现在点击之后停止了,但是重新播放无法生效,想知道有什么办法可以让重新播放生效
1 回复
play: function (){ var that = this const backgroundAudioManager = wx.getBackgroundAudioManager() backgroundAudioManager.title = '此时此刻' if (that.data.fg == 1){ backgroundAudioManager.src = 'https://cos-bi-ppt-1252899312.cos.ap-shanghai.myqcloud.com/word/ci/1.mp3' } else { backgroundAudioManager.src = 'https://cos-bi-ppt-1252899312.cos.ap-shanghai.myqcloud.com/word/ci/2.mp3' } backgroundAudioManager.onStop( function (){ console.log( "停止" ) }) backgroundAudioManager.onPlay( function (){ console.log( "开始" ) if (that.data.fg == 1){ that.setData({ fg: 2 }) } else { that.setData({ fg: 1 }) } }) backgroundAudioManager.onEnded( function (){ if (that.data.fg == 1) { that.setData({ fg: 2 }) } else { that.setData({ fg: 1 }) } }) } |
现在是多加了一个音频路径,在播放其中一个时,如果再次点击,就播放另一个音频。这样才能实现打断之前的播放并且__立即__重新播放的功能