tags:

views:

76

answers:

4

Hi,

I'm working on an app that uses AudioRecord class to get input data from the phone mic. For some reason I'm unable to mute the mic. I have tried with different AudioSources (DEFAULT, MIC and VOICE_UPLINK) when creating the AudioRecord object, but there's no difference in the muting behaviour.

The muting itself, I'm trying to achieve with AudioManager#setMicrophoneMute() method.

Any ideas?

Thanks.

+1  A: 

have you checked the android manifest permissions. Have you enabled that ??

the100rabh
Good point. I have previously set RECORD_AUDIO and MODIFY_AUDIO_SETTINGS permissions, do I need something more?The documentation of AudioManager#setMicrophoneMute(boolean) does not define that the method requires any permissions. Or in other words, it's not explicitly said that it needs some permissions. (Of course it might still need )
J Andy
Yes MODIFY_AUDIO_SETTINGS should be enough. I am guessing that ur using public void setMicrophoneMute (boolean on)to mute the microphone.
the100rabh
Yes, AudioManager#setMicrophoneMute(boolean on). The AudioManager#isMicrophoneMuted() method also returns correctly the state, the actual device just does not get muted.
J Andy
Hello,I am trying to mute the microphone frequently, can you share your knowledge? MY App freezes if I mute unmute in a loop.---------------------------- for (int i=0;i<30;i++) { audioService.setMicrophoneMute(false); Toast.makeText(getBaseContext(), "Un MUTED", 1).show(); try { Thread.sleep(1000,90); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } audioService.setMicrophoneMute(true); Toast.makeText(getBaseContext(), "MUTED", 1).show(); }
A: 

Sorry for the late update. No longer an issue. Our app uses a third party lib that was doing some audio stuff that caused trouble.

I marked my own answer as correct just to inform that this is no longer an open issue.

J Andy
Any chance you could be more specific I'm trying the same but I am not using any third party stuff and I have the same issue, I am controlling audio in the NDK layer though, is that what led to your issue?
Donal Rafferty
A: 

Hello, I am trying to mute the microphone frequently, can you share your knowledge? MY App freezes if I mute unmute in a loop.

for (int i=0;i<30;i++) { audioService.setMicrophoneMute(false); Toast.makeText(getBaseContext(), "Un MUTED", 1).show(); try { Thread.sleep(1000,90); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } audioService.setMicrophoneMute(true); Toast.makeText(getBaseContext(), "MUTED", 1).show(); }

A: 
for (int i=0;i<30;i++) { 
   audioService.setMicrophoneMute(false); 
   Toast.makeText(getBaseContext(), "Un MUTED", 1).show(); 
   try { 
      Thread.sleep(1000,90); 
   } 
   catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
   } 
   audioService.setMicrophoneMute(true); 
   Toast.makeText(getBaseContext(), "MUTED", 1).show(); 
}

OK. Now a bit more readable.

Seems like you are running this code in the UI thread. You'll probably get an Application Not Responding error, since your code block is executed for more than ~5 seconds. Seeing some logs would be helpful here.

You need to execute the code in a seperate thread, take a look at Handler.

J Andy