Component({
data: {
audio: null,
currentTime: 0,
duration: 0
},
attached() {
const audio = wx.createInnerAudioContext()
this.setData({ audio })
audio.src = "https://1257107138.vod2.myqcloud.com/288f6a2cvodsh1257107138/3291a5fe5285890810640015371/Wrtjv5effAcA.mp3" // 往前seek无效
// audio.src = "https://1257107138.vod2.myqcloud.com/c99bf365vodcq1257107138/bc830cfd5285890805589477059/KbZsADrsIiEA.mp3" // 正常seek
audio.onTimeUpdate(() => {
console.log('onTimeUpdate')
this.setData({
currentTime: audio.currentTime
})
})
const getDurationTimer = setInterval(() => {
if (audio.duration) {
clearInterval(getDurationTimer)
this.setData({ duration: audio.duration })
}
}, 100)
},
methods: {
moved(event) {
const audio = this.data.audio
audio.pause() // 修复seek后onTimeUpdate监听失效
audio.seek(event.detail.value)
setTimeout(audio.play, 50) // 修复seek后onTimeUpdate监听失效
},
play() {
this.data.audio.play()
},
pause() {
this.data.audio.pause()
},
stop() {
this.data.audio.stop()
}
}
})
<slider
class="slider"
value="{{ currentTime }}"
min="0"
max="{{ duration }}"
bindchange="moved"
></slider>
<button bindtap="play">播放</button>
<button bindtap="pause">暂停</button>
<button bindtap="stop">停止</button>
// ******************************************************************************************************************************************************
向左拖动音频进度条,触发seek事件,但是无效。(ios端和工具端正常)
这个问题会在7.0.23修复