Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mute MediaPlayer in android

How to mute MediaPlayer in android

like image 505
Parag Chauhan Avatar asked Jan 01 '11 09:01

Parag Chauhan


People also ask

How do I play music through MediaPlayer?

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.


2 Answers

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); 
like image 78
Parag Chauhan Avatar answered Oct 06 '22 07:10

Parag Chauhan


 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); 
like image 23
Ramesh Akula Avatar answered Oct 06 '22 07:10

Ramesh Akula