aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-12-04 08:40:56 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-12-04 08:40:56 -0800
commit3a18259bcd476be655b72309190aa1a7a932c241 (patch)
tree26699d42d2c3a724e99344dfe0e8174daad28587
parent0ff8a5bc4f8a6134675e961a3b0d1433ad9e4940 (diff)
parent7bfc9706d1bf162d3929c6ac1db3e43498b4b0b7 (diff)
Merge pull request #1894 from jvilk/legacy_fs_remove
[SDL Audio] Refactoring Mix_LoadWAV_RW to use new FS API.
-rw-r--r--src/library_sdl.js22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 67b63885..40e5e3ab 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1915,23 +1915,19 @@ var LibrarySDL = {
var filename = '';
var audio;
var bytes;
-
+
if (rwops.filename !== undefined) {
filename = PATH.resolve(rwops.filename);
var raw = Module["preloadedAudios"][filename];
if (!raw) {
if (raw === null) Module.printErr('Trying to reuse preloaded audio, but freePreloadedMediaOnUse is set!');
Runtime.warnOnce('Cannot find preloaded audio ' + filename);
-
+
// see if we can read the file-contents from the in-memory FS
- var fileObject = FS.findObject(filename);
-
- if (fileObject === null) Module.printErr('Couldn\'t find file for: ' + filename);
-
- // We found the file. Load the contents
- if (fileObject && !fileObject.isFolder && fileObject.read) {
- bytes = fileObject.contents;
- } else {
+ try {
+ bytes = FS.readFile(filename);
+ } catch (e) {
+ Module.printErr('Couldn\'t find file for: ' + filename);
return 0;
}
}
@@ -1946,16 +1942,16 @@ var LibrarySDL = {
else {
return 0;
}
-
+
// Here, we didn't find a preloaded audio but we either were passed a filepath for
// which we loaded bytes, or we were passed some bytes
if (audio === undefined && bytes) {
- var blob = new Blob([new Uint8Array(bytes)], {type: rwops.mimetype});
+ var blob = new Blob([bytes], {type: rwops.mimetype});
var url = URL.createObjectURL(blob);
audio = new Audio();
audio.src = url;
}
-
+
var id = SDL.audios.length;
// Keep the loaded audio in the audio arrays, ready for playback
SDL.audios.push({