Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Don't synchronously decode audio in Chrome. The Web Audio API is a go…
Browse files Browse the repository at this point in the history
…ddamn mess.
  • Loading branch information
kg committed Aug 6, 2012
1 parent ce6625b commit a8c24c6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Libraries/JSIL.Browser.js
Expand Up @@ -648,15 +648,25 @@ var loadWebkitSound = function (filename, data, onError, onDoneLoading) {
// Safari doesn't implement canPlayType, so we just have to hard-code MP3. Lame.
uri = contentRoot + filename + ".mp3";

loadBinaryFileAsync(uri, function (result, error) {
loadBinaryFileAsync(uri, function decodeWebkitSound (result, error) {
if (result !== null) {
var buffer = audioContext.createBuffer(result.buffer, false);
var finisher = function () {
$jsilbrowserstate.allAssetNames.push(filename);
allAssets[getAssetName(filename)] = new WebkitSoundAsset(getAssetName(filename, true), audioContext, buffer, data);
// THIS IS SO STUPID
// var buffer = audioContext.createBuffer(result.buffer, false);

var decodeCompleteCallback = function (buffer) {
var finisher = function () {
$jsilbrowserstate.allAssetNames.push(filename);
allAssets[getAssetName(filename)] = new WebkitSoundAsset(getAssetName(filename, true), audioContext, buffer, data);
};

onDoneLoading(finisher);
};

onDoneLoading(finisher);

var decodeFailedCallback = function () {
onError("Unknown audio decoding error");
};

audioContext.decodeAudioData(result.buffer, decodeCompleteCallback, decodeFailedCallback);
} else {
onError(error);
}
Expand Down

0 comments on commit a8c24c6

Please sign in to comment.