解决办法:
方法一:在onShow钩子函数中再绑定一次onTimeUpdate
onShow: function () {
let audioContext = this.data.audioContext;
audioContext.onPlay(() => {
audioContext.onTimeUpdate(() => {
let currentTime = audioContext.currentTime;
let duration = audioContext.duration;
this.setData({
['audio.duration']: this.formatTime(duration),
['audio.time']: this.formatTime(currentTime),
['audio.progress']: currentTime / duration * 100 * 0.95 + '%'
});
})
})
},
方法二:
如果不去读取innerAudioContext.paused这个变量,它不会主动更新。解决问题的思路就是在调用play()方法之后再主动读取一次paused变量。可以写一个settimeout函数。
this.data.audioContext.play();
setTimeout(() => {
console.log(this.data.audioContext.paused)
}, 100)