案發現場:
我的項目中 我將 myaudio = wx.createInnerAudioContext();定義在了 頁面 onload的裏面。
使用seek跳轉了以後。監聽事件失效了。
解決思路:
使用 myaudio.seek()。跳轉的時候,需要先將音頻暫停了,在跳轉,否則監聽事件就失效了
代碼
//播放/恢復音頻
play: function () {
this.myaudio.play();
this.setData({ isplay: true });
},
// 停止
stop: function () {
this.myaudio.pause();
this.setData({ isplay: false });
},
//進度條跳轉執行的函數
timeSliderChanged: function (e) {
let that= this
//暫停音頻
that.stop()
//跳轉到滑塊拖動位置
that.myaudio.seek(e.detail.value)
that.setData({
isAudioTrue: true
});
//恢復音頻
setTimeout(function () {
that.play()
}, 500)
},