How to mute MediaPlayer in android
Start/Pause the playback: After loading the media file, you can start playing the media file by using the start() method. Similarly, you can pause the playing media file by using the pause() method. Stop the playback: You can stop playback by using the reset() method.
This code worked for me,
MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1); mp.start();
for Mute
mp.setVolume(0,0);
& Unmute or full volume
mp.setVolume(1,1);
AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); int current_volume =mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); //If you want to player is mute ,then set_volume variable is zero.Otherwise you may supply some value. int set_volume=0; mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,set_volume, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With