Skip to content Skip to sidebar Skip to footer

Android Soundpool Heap Limits

I am using a SoundPool to load several sound clips into and play them back. It is functioning 100% correctly from what I can tell. But during the .load() calls I am getting my log

Solution 1:

SoundPool is going to decompress the loaded audio to PCM data so it is ready to play instantly without the latency of decoding. If the audio you are loading is compressed heavily, such as MP3, then that can get blown up quite a bit. Try encoding the audio as mono if stereo isn't necessary (it usually isn't for short sound effects).

Solution 2:

SoundPool has 1Mb buffer size limit per track. But this limit applies not to file size but to decompressed raw PCM data.

I suggest to use SoundPoolCompat from 3d party library. It has similar api to SoundPool, but has custom buffer size, all data within that buffer will be loaded into memory and played with small latency like SoundPool does. All data that exceed that buffer size will be loaded on demand (which adds latency, similar to MediaPlayer). But it will not crash nor play data that's only fits buffer size like SoundPool. Also buffer size is expressed in file size not in decompressed data size. Which is more convenient to api user.

implementation 'com.olekdia:sound-pool:3.2.0'

https://gitlab.com/olekdia/common/libraries/sound-pool

Post a Comment for "Android Soundpool Heap Limits"