How does setMicrophoneMute() work?

前端 未结 3 2151
挽巷
挽巷 2020-12-02 15:54

I have been trying to use Android\'s AudioManager.setMicrophoneMute() without much success. That is, it simply refuses to mute the microphone, no matter what I

3条回答
  •  离开以前
    2020-12-02 16:12

    I found the same issues on samsung Galaxy and I solved it by using MODE_IN_COMMUNICATION mode.

    In the AudioManager.java source codeit says :

    1. MODE_IN_CALL - In call audio mode. A telephony call is established.
    2. MODE_IN_COMMUNICATION - In communication audio mode. An audio/video chat or VoIP call is established.

    Because i use the third VOIP library, I use the MODE_IN_COMMUNICATION and it solved the issue.

    AudioManager audioManager = (AudioManager)
    context.getSystemService(Context.AUDIO_SERVICE);
    // get original mode 
    int originalMode = audioManager.getMode();
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    // change mute 
    boolean state = !audioManager.isMicrophoneMute();
    audioManager.setMicrophoneMute(state);
    // set mode back 
    audioManager.setMode(originalMode);
    

提交回复
热议问题