1

So I am using soundpool to play a sound at the end of a timer. onCreate I am doing this

int mySoundId;
SoundPool soundPool;

// load sound

soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

AssetManager am = this.getAssets();

//Use in whatever method is used to load the sounds
try {
    mySoundId = soundPool.load(am.openFd("alarm.wav"), 1);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

I was getting

sample 0 not READY

So I figured out I had to use

soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
    @Override
    public void onLoadComplete(SoundPool soundPool, int mySoundId, int status) {
        loaded = true;
    }
});

But my problem is, setOnLoadCompleteListener gives me the following error

The method setOnLoadCompleteListener(SoundPool.OnLoadCompleteListener) in the type SoundPool is not applicable for the arguments (new OnLoadCompleteListener(){})

I have tried various things, such as "Android Tools -> Fix Project Properties" and fiddling with "Properties -> Java Compiler" but no joy. My API range is 10 - 16 so it should be ok. Any ideas what its having issues with?

Community
  • 1
  • 1
Horse
  • 3,023
  • 5
  • 38
  • 65
  • interesting, someone upvoted this mere seconds after i posted it! couldnt have had time to read it? – Horse Aug 30 '12 at 20:51

2 Answers2

3

Use below code. Maybe your imports are wrong. Anyway this should work

soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
    @Override
    public void onLoadComplete(SoundPool soundPool, int mySoundId, int status) {
        loaded = true;
    }
});
bialix
  • 20,053
  • 8
  • 46
  • 63
nandeesh
  • 24,740
  • 6
  • 69
  • 79
  • sorry, have had to put this down for a bit, I will make sure I accept your answer when I get back to it if correct, thanks! – Horse Sep 12 '12 at 13:33
  • well, it sort of works, now it says - error opening trace file: No such file or directory (2) – Horse Sep 15 '12 at 01:31
0

I had the same problem, and then I noticed that I simply had to import android.media.SoundPool.OnLoadCompleteListener...