Listing 21.1: SoundPool.Builder usage

Istead of just using deprecated constructor, why not to write here something like this:

    AudioAttributes attributes = new AudioAttributes.Builder()
    mSoundPool = new SoundPool.Builder()
} else {
    //noinspection deprecation
    mSoundPool = new SoundPool(MAX_SOUNDS, AudioManager.STREAM_MUSIC, 0);


1 Like

That’s a better way to do it. I would write similar code in a real project. :+1:

For the purposes of the book, code like this adds an additional hurdle towards understanding how SoundPool works. In general, we try to write less code so that the reader can understand the core concepts.

1 Like