I want to use a mute button inside my app as bellow :
ImageView muteMusic = (ImageView) findViewById(R.id.muteMusic);
mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
public void mute(View v) {
switch (mAudioManager.getRingerMode()) {
case AudioManager.RINGER_MODE_NORMAL:
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
break;
case AudioManager.RINGER_MODE_SILENT:
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
break;
}
}
XML
<ImageView
android:id="@+id/muteMusic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="120dp"
android:layout_toRightOf="@id/info"
android:onClick="mute"
android:src="@drawable/volbutton" />
but its not working , I dont know why ! no errors and no crashes ! but it does not make any action when I click on it
The problem is that you’re muting the ringer instead of your music stream.
Instead of using
use
Please refer to the API documentation for information on how to manage muting/unmuting within your application regarding releasing resources.