HTML5播放语音时 音频解析出错 Unable to decode audio data 无法解析音频数据

window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext;
var audioContext = new window.AudioContext();

function playSound(soundBuffer) {
console.log('do play sound');
console.log(soundBuffer.buffer);

audioContext.decodeAudioData(soundBuffer.buffer,function(audioBuffer){
    console.log(audioBuffer);
    var sourceNode = audioContext.createBufferSource();
    sourceNode.connect(audioContext.destination);
    sourceNode.buffer = audioBuffer;
    sourceNode.start();
},function(err){
    console.log(err);
})

}

function loadNotificationForNewMsg(newMsg) {

playSound(newMsg.msgData);

}

client.msgHandler = function (newMsg) {

loadNotificationForNewMsg(newMsg);

}
下图为newMsg.msgData参数

clipboard.png

报错信息

clipboard.png

阅读 12.4k
2 个回答

你播放的语音格式不支持吧

新手上路,请多包涵

解码音频溢出也会报错

推荐问题