I have a problem with my code its supposed to stop the button when clicked on so like i click on Button1 it plays click on Button1 again it stops etc. etc. and also for other buttons the same works and when you click on Button2 for example Button1 Stops
I have 74 buttons and this is in oncreate for all of them
Button1Text = (Button) findViewById(R.id.Button1Text);
Button1Text2 = (Button) findViewById(R.id.Button1Text2);
this is the code for the button
public void Button1Text(View view) {
normalButton();
Button1Text.setBackgroundResource(R.color.lighterbrown);
releaseAll();
media1 = MediaPlayer.create(QuranJ30MA.this, R.raw.hannaba);
media1.start();
}
public void Button1Text2(View view) {
normalButton();
Button1Text2.setBackgroundResource(R.color.lightergreen);
releaseAll();
media2 = MediaPlayer.create(QuranJ30MA.this, R.raw.mannaba);
media2.start();
}
this is the "releaseMP" function that supposed to do what i want it to do but doesnt work in this app while it works in other apps
private void releaseMP(MediaPlayer mediaPlayer) {
try {
if (mediaPlayer != null) {
if (mediaPlayer.isPlaying())
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
this is the "releaseAll();" function
private void releaseAll() {
releaseMP(media1);
releaseMP(media2);
i think thats all also the "normalButton();" just resets colors
i tried to copy it exactly the same from other codes of my other apps(note they work in those apps but not here) i dont understand where i went wrong this is a problem i have had for days
Set startRecodingButton with OnClickListener:
Check MediaRecorder is null or not.