开发者

Android MediaPlayer Mute and unmute

开发者 https://www.devze.com 2023-04-08 12:01 出处:网络
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 开发者_高级运维

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号