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.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)复现频率很高)
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
请问楼主如何解决的,分享下