Android SoundPool heap limits

无人久伴 提交于 2019-12-24 04:42:07

问题


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 should be altering to avoid this overflow? Any guidance on how I should be setting up my audio controls would be much appreciated.


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




回答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.0.2'

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



来源:https://stackoverflow.com/questions/6296361/android-soundpool-heap-limits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!