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.2k
2 个回答

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

新手上路,请多包涵

解码音频溢出也会报错

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题