Load audio / sound files on android


as far as my understanding goes, you can either embed assets, download external assets, or load them from your internal storage. What I am trying to do (and failing at) is loading and playing back sound files, that are stored on my android device (not necessarily in the application storage folder).

What I tried so far on android:

bytes = File.getBytes(filepath);
sound = new Sound();
sound.loadCompressedDataFromByteArray(bytes.getData(), bytes.length);

It did successfully load all the bytes, but then crashed when I tried to call sound.loadCompressedDataFromByteArray() / loadPCMFromByteArray().
The other thing I tried was:

sound = Sound.fromAudioBuffer(AudioBuffer.fromFile(filepath));

Both of those solutions are working just fine when targeting windows, so I am a bit lost here.

In case anybody will be suggesting it:
sound = Assets.getSound(soundId)
sound = new Sound(new URLRequest(filepath));
Using the Assets class or an URLRequest is as far as my understanding goes not applicable here.

Looking forward to some replies!

I just found and tried that with the same result, working on windows not working on android:
sound = Sound.fromFile(filepath);
it just returns a sound object with sound.length = 0

Am I missing any permissions? I only added the “READ_EXTERNAL_STORAGE” permission so far.


1. bytes = File.getBytes(filepath);
2. trace(bytes.getDouble(i));

On both windows and android I can execute the first line, the seoncd line traces an arbitraty number on windows, but just crashes the app on android. The output I get on the adb monitor logcat is:
"Fatal signal 7 (SIGBUS) at 0x00000000 (code=128), thread 23472 (SDLThread)"

Since the path I was trying to read from was something like:
I am assuming the issue was, that I was trying to access emulated storage that only existed virtually so each attempt to read something resulted in a crash.

For now I went back to only reading files that are located in the app storage directory.