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参数
报错信息
你播放的语音格式不支持吧