Написал так, результата нет. Или я что-то не так сделал?
var audio = new Audio;
audio.addEventListener("canplaythrough", function() {
finish(audio)
}, false);
audio.onerror = function audio_onerror(event) {
if (done) return;
console.log("warning: browser could not fully decode audio " + name + ", trying slower base64 approach");
function encode64(data) {
var BASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var PAD = "=";
var ret = "";
var leftchar = 0;
var leftbits = 0;
for (var i = 0; i < data.length; i++) {
leftchar = leftchar << 8 | data[i];
leftbits += 8;
while (leftbits >= 6) {
var curr = leftchar >> leftbits - 6 & 63;
leftbits -= 6;
ret += BASE[curr]
}
}
if (leftbits == 2) {
ret += BASE[(leftchar & 3) << 4];
ret += PAD + PAD
} else if (leftbits == 4) {
ret += BASE[(leftchar & 15) << 2];
ret += PAD
}
return ret
}
audio.src = "data:audio/x-" + name.substr(-3) + ";base64," + encode64(byteArray);
finish(audio)
console.log("Audio1");
};
audio.src = url;
Browser.safeSetTimeout(function() {
finish(audio)
console.log("Audio2");
}, 1)