Search code examples
androidmedia-playermute

Android MediaPlayer Mute and unmute


I am playing a video using MediaPlayer. Now there is a mute/unmute button. This toggle button should set first the video play without sound, on second press it should make its volume to its initial state. I tried with AudioManager.setMicrophoneMute method. It did not work. How it can be done?


Solution

  • You can use AudioManager.setStreamMute(int streamType, boolean on) Setting it to true will change stream's volume to 0, and false restores volume value. More information at http://developer.android.com/reference/android/media/AudioManager.html#setStreamMute(int,boolean)