I have a program with a function copied below it plays a sound upon clicking a button. If you click the button 10 times 10 different media players play the same sound that is the way i want it but how can i assign a button to stop all 10 media players at a time like a "STOP ALL BUTTON"
public void onClick(View v){
int resId = 0;
int stopped = 0;
switch (v.getId()){
case R.id.Wail:
resId = R.raw.fedsigwail;
break;
case R.id.Yelp:
resId = R.raw.fedsigyelp;
break;
case R.id.HiLow:
resId = R.raw.hilow;
break;
case R.id.FederalQ:
resId = R.raw.federalq;
break;
case R.id.Horn:
resId = R.raw.fedsignhorn;
break;
case R.id.STOPALL:
mp.stop();
mp.release();
stopped = 1;
break;
}
if (stopped != 1){
mp = MediaPlayer.create(this, resId);
mp.start();
}
}
The code above only stops the last instance of mp.
Any Input would be appreciated