Soundpool sample not ready

SteD picture SteD · Mar 5, 2011 · Viewed 29.3k times · Source

I have a .wav file that I'd like to use across my game, currently I am loading the sound in onCreate() of each activity in the game.

 soundCount = soundpool.load(this,R.raw.count, 1);

The sound will be played once the activity starts.

  soundpool.play(soundCount, 0.9f, 0.9f, 1, -1, 1f);

Problem is at times I will hit the error "sample x not ready". Is it possible to load the .wav file once upon starting the game and keep it in memory and use it later across the game? Or is it possible to wait for 1-2 seconds for the sound to load finish?

Answer

EboMike picture EboMike · Mar 5, 2011

You'll need to wait for it to finish by adding a listener via SoundPool.setOnLoadCompleteListener.