Simplify audio loading, use AudioBuffer.loadFile(s)

This commit is contained in:
Joshua Granick
2016-10-05 15:30:21 -07:00
parent 944084d6ac
commit 31dacebe5e
3 changed files with 129 additions and 43 deletions

View File

@@ -472,46 +472,20 @@ class DefaultAssetLibrary extends AssetLibrary {
var promise = new Promise<AudioBuffer> ();
#if flash
if (path.exists (id)) {
if (Assets.isLocal (id)) {
var soundLoader = new Sound ();
soundLoader.addEventListener (Event.COMPLETE, function (event) {
var audioBuffer:AudioBuffer = new AudioBuffer();
audioBuffer.src = event.currentTarget;
promise.complete (audioBuffer);
});
soundLoader.addEventListener (ProgressEvent.PROGRESS, function (event) {
if (event.bytesTotal == 0) {
promise.progress (0);
} else {
promise.progress (event.bytesLoaded / event.bytesTotal);
}
});
soundLoader.addEventListener (IOErrorEvent.IO_ERROR, promise.error);
soundLoader.load (new URLRequest (path.get (id)));
promise.completeWith (new Future<AudioBuffer> (function () return getAudioBuffer (id)));
} else if (path.exists (id)) {
promise.completeWith (AudioBuffer.loadFile (path.get (id)));
} else {
promise.complete (getAudioBuffer (id));
promise.error (null);
}
#else
promise.completeWith (new Future<AudioBuffer> (function () return getAudioBuffer (id)));
#end
return promise.future;
}