Android : How to mute the android app using toggle button in android?

on Thursday, September 4, 2014


I am using toggle button for mute and unmute the app sounds .When mute button is pressed I want to mute all the sounds in app.I am using media player for playing sounds .How to mute and unmute the media player using toggle button.


Here is my code ,



mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.tone_uyir_mei_ezhuthukal);
mediaPlayer.start();




toggleButton=(ToggleButton) findViewById(R.id.toggleButton1);
toggleButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
StringBuffer result = new StringBuffer();
result.append(toggleButton.getText());
Toast.makeText(HomeScreen.this, result.toString(),
Toast.LENGTH_SHORT).show();
if (result.equals("volume")) {

}else {

}

}
});


I did not know how to proceed .Need help to mute and unmute the app using this toggle button


0 comments:

Post a Comment