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?
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)
The setMicrophoneMute()
mutes the microphone (obviously), this is an input device. Microphone does not participate in audio playback and therefore muting it has no effect.
You can use MediaPlayer.setVolume()
to mute/unmute the output. For an idea how to implement this see this thread.
精彩评论