I'm trying to loop a sound while a button is pressed down.
How could I do that while I'm pressing the button hadling the event "MotionEvent.ACTION_DOWN" will not stop running the sound? The way I have done it only runs once. I've tryied to change the return statement to false, but it doesn't works.
The setLoop MediaPlayer option does not help me because I want to continue playing new sounds although the current sound doesn't finished playing.
Here's my code:
public boolean onClick(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
//here should not stop running the soundPool
soundPool.play(R.raw.sound1, 1, 1, 1, 0, 1);
}
if(event.getAction() == MotionEvent.ACTION_UP){
// stop running the soundpool
}
return true;
}
Replace the fifth argument to -1 :
soundPool.play(R.raw.sound1, 1, 1, 1, -1, 1);
As of the play() doc the fifth argument loop takes either 0 ( = no loop), or -1 ( = loop forever)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With