is it possible to mute a call while recording the sound in android

一笑奈何 提交于 2019-12-22 11:36:07

问题


I want to build a app where I want to modulate the sound in a call.I have written a code that record the sound nd play it in different pitch.Now I want this feature while calling.I want to mute the call record the sound then play it with diff pitch.How to mute the call but still record the audio.


回答1:


This answer works to mute your microphone during a call:

Boolean isMuted = false;

Then in your event, say an onClick

AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if(!isMuted){

   if((audioManager.getMode()== AudioManager.MODE_IN_CALL)||(audioManager.getMode()== AudioManager.MODE_IN_COMMUNICATION)){
   audioManager.setMicrophoneMute(true);
  }
  isMuted = true;

 }else{

  if((audioManager.getMode()== AudioManager.MODE_IN_CALL)||(audioManager.getMode()== AudioManager.MODE_IN_COMMUNICATION)){
    audioManager.setMicrophoneMute(false);
    }
  isMuted = false;
 }

Remember to enable permissions in your manifest:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />



回答2:


Step 1. set permission in manifest

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Step 2. reverse microphone status

AudioManager audioManager = 
     (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager!=null) {
     audioManager.setMicrophoneMute(!audioManager.isMicrophoneMute());
}



回答3:


I couldn't make AudioManager.setMicrophoneMute(boolean) work on my Honor device, but I found another way to do this. I needed this funcionality in my custom dial app, so I already had custom InCallService, intercepting all calls. This class has method setMuted(boolean state) which works perfectly.



来源:https://stackoverflow.com/questions/29454511/is-it-possible-to-mute-a-call-while-recording-the-sound-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!