• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Soundpool Multiple funtions, one action

how can i assign two actions to one button

i've tried this
Code:
bHat_cl.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
	if (event.getAction() == MotionEvent.ACTION_DOWN) {
		sp.play(hat_cl, 1, 1, 1, 0, 1);
		sp.stop(hat_op);
		return true;
	}
	return false;
}
		});
 
You need to cteate a flag variable (usually boolean) that keeps track of the state of the action. Fortunatly, the MediaPlayer class already keeps track of a flag for you, just for this scenario. Inside the onClick() method, you need something like the following:

Code:
if (mp.isPlaying()) {
    mp.stop();
} else {
    mp.start();
}
 
You need to cteate a flag variable (usually boolean) that keeps track of the state of the action. Fortunatly, the MediaPlayer class already keeps track of a flag for you, just for this scenario. Inside the onClick() method, you need something like the following:

Code:
if (mp.isPlaying()) {
    mp.stop();
} else {
    mp.start();
}

the problem is, that i have the open hihat soun playing,
and i want that to stop when i play the closed hihat sound,
how would i do that
 
Back
Top Bottom