真机调试 点击播放 然后再暂停 继续播放 有时候会触发到innerAudioContext.onPause暂停事件 就播放不了了
uni.createInnerAudioContext()暂停再播放有时候会卡住?//暂停播放音频 pauseVoice() { innerAudioContext.pause() this.voiceShow = false console.log('暂停'); }, // // 播放音频 playVoice() { innerAudioContext.src = https://wakaka-1311155419.cos.ap-guangzhou.myqcloud.com/wakaka/voice/20230105/9uY2CCoAu7CiZtDgTjJgAl8qAyySgaU0skruO8Qo.mp3 innerAudioContext.play() console.log('播放地址',innerAudioContext.src); innerAudioContext.onPlay(() => { console.log('开始播放') this.voiceShow = true }) innerAudioContext.onCanplay(() => { innerAudioContext.duration // setTimeout(() => { // //保存总时长,这里需要用到定时器,让函数延迟执行,不然获取不到值 // //innerAudioContext对象中的duration和buffered代表音频总时长 // console.log(480,innerAudioContext.duration) // }, 10) }) innerAudioContext.onTimeUpdate(() => { this.audioForm.times = innerAudioContext.duration.toFixed(0) console.log('音频时长', this.audioForm.times); //innerAudioContext对象中的currentTime代表当前音频播放到第几秒了。 //用总时长减去当前播放的到第几秒了,然后赋值给倒计时,就实现了倒计时的功能。 this.audioForm.duration = this.audioForm.times - innerAudioContext.currentTime.toFixed(0) console.log('播放中', this.audioForm.duration); }) innerAudioContext.onPause(()=>{ // innerAudioContext.play() console.log('暂停事件'); }) innerAudioContext.onEnded(() => { console.log('结束'); this.voiceShow = false }) }, [图片] [图片]
2023-01-06