请问楼主如何解决的,分享下
InnerAudioContext短时间内频繁更换音频地址并play()在差手机上会频繁出现多个声音let listener = null,audioContext = null; const audioList = [ '/Wsp/File/Download/21189778427876858', '/Wsp/File/Download/21122842704905247', '/Wsp/File/Download/21141684725357527', '/Wsp/File/Download/21140548707059953', '/Wsp/File/Download/21141730896281559', '/Wsp/File/Download/21140021231082737' ]; var audioIndex = 0; const maxIndex = audioList.length - 1; // 识别相关 createListener(){ let num = 0,self = this; const context = wx.createCameraContext(); listener = context.onCameraFrame(async function (res) { num++; if (num === 50) { num = 0; if (audioIndex === maxIndex) { audioIndex = 0; } else { audioIndex++; } audioContext.src = 'https://wall.alva.com.cn' + audioList[audioIndex]; audioContext.play(); } }); listener.start(); }, // 音频相关 initAudio(){ let self = this; audioContext = wx.createInnerAudioContext(); // audioContext.loop = true; audioContext.onPlay(() => { self.setData({ audioPlay: true }) }); audioContext.onEnded(() => { console.log('audio onEnded') self.setData({ audioPlay: false }) }); audioContext.onPause(() => { self.setData({ audioPlay: false }); }); }, 期望表现:更换InnerAudioContext的src后,调用play()只播放新地址的音频; 实际结果:有时更换src前的音频和更换src后的音频同时在播放(在好的手机上偶现,非必现,差的手机上(华为P20)复现频率很高)
2021-07-23