Search code examples
androidaudiosoundpool

Soundpool vs Mediaplayer for playing multiple sound effects


I'm building an app that plays multiple short sound effects in one activity. There are over 80 buttons with each buttons that plays a specific sound effect. I've searched about SoundPool and MediaPlayer and found out SoundPool is more efficient for short sound files.

Here's my question, if I should load over 80 sound effects in one activity, would SoundPool still be the better option? I ask because SoundPool loads the sound at once and reuses it, I think it's a bit heavy to load 80 sounds in one activity (Maybe I'm wrong.) Would like to hear the experts here for a better way or any advice!

Thanks in advance


Solution

  • It does not depend by the number of sounds, but from their size in terms of bytes. Every sound is loaded into memory and if they are too big, you could not have enough memory to load them all.

    I would consider using AudioTrack. You instantiate it and when you have to play a sound you can read it from file system or assets or resources and add it to the play queue. It works only with PCM.