Permalink
Browse files

Don't synchronously decode audio in Chrome. The Web Audio API is a go…

…ddamn mess.
  • Loading branch information...
1 parent ce6625b commit a8c24c6062d378a80707b2b1812fec7d8c6b29a6 @kg kg committed Aug 6, 2012
Showing with 17 additions and 7 deletions.
  1. +17 −7 Libraries/JSIL.Browser.js
View
@@ -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);
}

0 comments on commit a8c24c6

Please sign in to comment.