废话不多说,直接这么写就可以解决:
innerAudioContext.play();
innerAudioContext.onCanplay(() => {
innerAudioContext.play();
console.log('开始播放')
});
innerAudioContext.onWaiting(() => {
innerAudioContext.pause()
});
主要涉及这几个方法
//播放声音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===")}});},