Now you can Subscribe using RSS

Submit your Email


SoundPool constructor deprecated since API level 21

Vishal Shrestha
The good ol' constructor: SoundPool(int maxStreams, int streamType, int srcQuality) was deprecated in API level 21. We now need to use SoundPool.Builder to create soundPool instance. To use SoundPool in the device running API level >= 21 and API level < 21 just use the following code :

     mSoundPool = new SoundPool.Builder()
} else {
    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 1);
Now you can simply use the reference mSoundPool to play sounds as you would usually do.
Keep in mind that I have not used audioAttributes in the example above. If you don't provide an attribute, the default usage value is USAGE_MEDIA. You can use setAudioAttributes(AudioAttributes) to change them. Learn more about it - SoundPool.Builder() .You can also learn more about the common problems while using soundPool here : SoundPool not Playing sound.

Vishal Shrestha / Author & Founder

A developer by profession, a born Adventurer. I mainly do Android but like to get my hands dirty with web development and a little bit of Python. I would't rather go on a Trek than a party and you can find me having a few rounds with the heavy bag to let out the steam ;)


Research and Development at : Ekghanti

Mobile Technology Lead at : Vimvox Lab

For Business info : My Portfolio Site


Post a Comment

Coprights @ 2017 | The Code City by Vishal Shrestha Vishal Shrestha