Search code examples
javaandroidlibgdxassets

AssetManager loads sound too slow on android


I want to load the 'bang.ogg' file from my assets folder using the LibGDX AssetManager:

am.load("bang.ogg", Sound.class);
am.finishLoading();

On my Xiaomi Redmi 4X it takes 2 minutes to load this 42Kb-sound! Apk size is 2Mb.

I load an image. But it loads in mills:

am.load("test.jpg", Texture.class);

What I have to do? What causes this problem?


Solution

  • The problem with the Sound implementation is that it will load the entire file into memory. According to the wiki you should not use it on Android if the file size exceeds 1MB:

    note: On Android, a Sound instance can not be over 1mb in size. If you have a bigger file, use Music

    Your audio is smaller than 1MB but using the Music implementation allows you to stream the audio so it will not get loaded on startup but streamed while playing:

    For any sound that's longer than a few seconds it is preferable to stream it from disk instead of fully loading it into RAM. Libgdx provides a Music interface that lets you do that.

    I would give that one a try.