Android’s SoundPool not playing any sound, sample not ready | FIX

The SoundPool is a very useful class for playing and managing audio resources in Android applications. While using SoundPool class is fairly easy, there are  two different constructors that we can use to initialize the SoundPool class, one is for API version less than 21, and one is for API version 21 and greater. You can check both of them out here – Android SoundPool Constructor deprecated.

SoundPool Class Android

Most common problems as to why the sound player is not playing any sound are :

  1. SoundPool sample 1 not Ready problem.
  2. Before SoundPool can be used, we need to make sure the resources are properly loaded and soundpool is ready to be use. Otherwise when you call the play method, you will get the sampe 1 not Ready message and you won’t hear anything played. To fix this just use onLoadComplete listener and play the sound in side the onLoadComplete callback. Here’s how you use it:

    soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
    @Override
    public void onLoadComplete(SoundPool soundPool, int sampleId,
    int status) {
    soundPool.play(yourresID, 1, 1, 1, 0, 1)
    ;
    }
    });

  3. Not passing proper resourse ID to the play method of the SoundPool class.
  4. In order to play sound from a resource you need to pass the ID that is generated using the load method of soundPool Class, here’s an example :

    int mysound = soundPool.load(this, R.raw.mysound, 1);
    soundPool
    .play(mysound, 1, 1, 1, 0, 1);

That’s all, hope your problem is fixed and you can play sounds using SoundPool, check out the new constructor for SoundPool class here – Android SoundPool Constructor deprecated.
If you have any problems, feel free to message me or comment your problem down below! Cheers.

Don’t miss these tips!

We don’t spam! Read our privacy policy for more info.

You’ve been successfully subscribed to our newsletter! See you on the other side!

Sharing is caring!

1 thought on “Android’s SoundPool not playing any sound, sample not ready | FIX”

Leave a Comment

Your email address will not be published.

Exit mobile version