解决方法
使用网络音频api直接计算出来,在iOS和Android的移动浏览器中具有最佳兼容性.
function base64ToArrayBuffer(base64) { var binaryString = window.atob(base64); var len = binaryString.length; var bytes = new Uint8Array( len ); for (var i = 0; i < len; i++) { bytes[i] = binaryString.charCodeAt(i); } return bytes.buffer; } var base64 = '<data string retrieved from server>'; var audioContext = new (window.AudioContext || window.webkitAudioContext)(); var source = audioContext.createBufferSource(); audioContext.decodeAudioData(base64ToArrayBuffer(base64),function(buffer) { source.buffer = buffer; source.connect(audioContext.destination); source.start(0); });
它适用于iOS Safari,Chrome和Android默认浏览器和Chrome.