問題描述:
微信小程式在較新版本的音頻介面中推薦使用InnerAudioContext物件實作音頻的播放、暫停、跳轉等功能,通過監聽介面回呼實作,
InnerAudioContext.onTimeUpdate(function callback)為監聽播放進度更新的介面,在拖動進度條時或跳轉播放后此回呼不觸發,
解決方案
將下面代碼粘貼到onReady中,使當onWaiting觸發后,立即呼叫play()觸發播放函式
// 音頻由于網路等原因等待中的回呼
this.audioCtx.onWaiting(() => {
that.audioCtx.pause() // 等待網路的時候音頻暫停
that.setData({
waitFlag: true // 標明是onWaiting觸發的暫停
})
})
// 音頻準備就緒的回呼
this.audioCtx.onCanplay(() => {
if (that.data.waitFlag) { // 如果是onWaiting觸發的暫停,就立即播放
that.audioCtx.play() // play()方法看上去能重新觸發onTimeUpdate()回呼
that.setData({
waitFlag: false // 取消相應的flag標志位
})
}
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/337850.html
標籤:其他
