开发者

Android SoundPool heap limits

开发者 https://www.devze.com 2023-03-12 06:43 出处:网络
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 spammed with:

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 spammed with:

06-09 11:30:26.110: ERROR/AudioCache(23363): Heap size overflow! req size: 1050624, max size: 1048576

I am loading in 11 sound files, of those 2 are very small ~3kb and the rest are between 10kb - 15kb. Windows is reporting

Size: 114kb

Size on disk: 128kb

Am I pushing the limits of what SoundPool is capable of holding? Is there some setting I sho开发者_如何转开发uld be altering to avoid this overflow? Any guidance on how I should be setting up my audio controls would be much appreciated.


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).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消