Search code examples
androidaudioloadsoundpool

Android soundpool not working


when I try to run soundpool in my program, it keeps giving me an error.

firstly, I added

SoundPool sp;

int shot = 0;

at the beginning of the program. Then I tried to add sound in the method that I wanted it to run by adding the following code,

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

shot = sp.load(this, R.raw.sound, 1); 

However, it keeps underlining .load and kept saying "The method load(Context, int, int) in the type SoundPool is not applicable for the arguments (GameView, int, int)"

How can I fix this?


Solution

  • You can't pass a view as the first parameter, it needs to be a context. Use this.getContext() instead.