diff options
author | John Vilk <jvilk@cs.umass.edu> | 2013-12-03 14:13:03 -0500 |
---|---|---|
committer | John Vilk <jvilk@cs.umass.edu> | 2013-12-03 14:13:03 -0500 |
commit | 7bfc9706d1bf162d3929c6ac1db3e43498b4b0b7 (patch) | |
tree | 3f619ac7e85529679ed311ad1c2767b3b5392e7d /src | |
parent | 205d1f08541b5fc6f4c667b5d8064806319a13af (diff) |
[SDL Audio] Refactoring Mix_LoadWAV_RW to use new FS API.
The old API was causing issues with certain file systems, as the `read` property required the execute bit AND the read bit to be set before it would return `true`.
As a side benefit, the new code is simpler and cleaner.
Diffstat (limited to 'src')
-rw-r--r-- | src/library_sdl.js | 22 |
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({ |