Android Soundpool Heap Limits
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'
Post a Comment for "Android Soundpool Heap Limits"