const audioCtx = wx.createWebAudioContext();
saveBinaryToLocal(data) {
const dataBuffer = wx.base64ToArrayBuffer(data);
audioCtx.decodeAudioData(dataBuffer, (buffer) => {
if (!this.audioBuffer) {
console.log(buffer)
this.audioBuffer = buffer;
this.playAudio()
} else {
const newBuffer = audioCtx.createBuffer(this.audioBuffer.numberOfChannels, this.audioBuffer.length + buffer.length, this.audioBuffer.sampleRate);
newBuffer.getChannelData(0).set(this.audioBuffer.getChannelData(0));
newBuffer.getChannelData(0).set(buffer.getChannelData(0), this.audioBuffer.length);
this.audioBuffer = newBuffer;
console.log(this.audioBuffer)
}
}, (err) => {
console.log(`decodeAudioData error: ${err}`);
})
}
playAudio() {
console.log('开始播放')
const source = audioCtx.createBufferSource();
source.buffer = this.audioBuffer;
source.connect(audioCtx.destination);
source.addEventListener('error', (error) => {
console.error('音频播放出错:', error);
this.isPlaying = false;
});
source.addEventListener('start', () => {
console.log('音频开始播放');
this.isPlaying = true;
});
source.start();
}
data数据是二进制加密的base64 请问哪里有问题导致播放不出来。
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。