废话不多说,直接这么写就可以解决:
innerAudioContext.play();
innerAudioContext.onCanplay(() => {
innerAudioContext.play();
console.log('开始播放')
});
innerAudioContext.onWaiting(() => {
innerAudioContext.pause()
});文章来源:https://uudwc.com/A/4P1rW
主要涉及这几个方法文章来源地址https://uudwc.com/A/4P1rW
//播放声音
play: function () {
console.log('==播放声音==')
innerAudioContext.autoplay = false,
innerAudioContext.src = this.data.tempFileVoicePath,
innerAudioContext.play();
innerAudioContext.onCanplay(() => {
innerAudioContext.play();
console.log('开始播放')
});
innerAudioContext.onWaiting(() => {
innerAudioContext.pause()
});
innerAudioContext.onTimeUpdate(() => {
console.log("==当前时间==" + Math.floor(innerAudioContext.currentTime) + "==音频时间==" + Math.floor(innerAudioContext.duration));
if (Math.floor(innerAudioContext.currentTime) == Math.floor(innerAudioContext.duration)) {
console.log("===时间stop===")
}
});
},