Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the size limit for SoundPool in Android?

Tags:

android

Is there a size limit for SoundPool in Android ? In this article, it says the sounds played with SoundPool should not exceed 1MB .

I need to play multiple sounds simultaneously, And at times, I may exceed the 1MB limit. can I rely on SoundPool for this? As I couldn't find an in depth guide on SoundPool, a clear Answer will be much appreciated :)

like image 940
OBX Avatar asked Dec 10 '25 17:12

OBX


1 Answers

SoundPool is very limited, yes it has hardcoded buffer size limit, and if you exceed it you will get silence with error in logcat. Also it is written in native cpp and it is hard to debug what happend. Different versions of Android have specific issues.

I have written SoundPoolCompat which uses AudioTrack under the hood. You could pass custom bufferSize, and all data within that buffer will be loaded into memory and played with small latency like SoundPool does. All data that exceed that bufferSize will be loaded on demand (which adds latency, similar to MediaPlayer). Api is very similart to SoundPool, also it is added loading sound from Uri (for example gdrive). And there is playOnce method, all resources will be unloaded after file is played. I use it in my apps insted of SoundPool and MediaPlayer as well.

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

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

like image 135
Oleksandr Albul Avatar answered Dec 12 '25 06:12

Oleksandr Albul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!