SoulRayder
SoulRayder

Reputation: 5166

How to mute audio in headset but let it play on speaker programmatically?

I am searching a work-around for my problem specified in this question:

How to disable the wired headset programmatically in Java

As mentioned there, I am getting audio in both my speakers and headphones.

Can someone please tell me how to mute the audio in the headset programmatically, while letting it play undiminished on speaker?

Upvotes: 2

Views: 6175

Answers (2)

Jatinkumar Patel
Jatinkumar Patel

Reputation: 1104

AudioManager mAudioMgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); mAudioMgr.setSpeakerphoneOn(true); mAudioMgr.setMode(AudioManager.MODE_IN_COMMUNICATION);

Upvotes: 0

noelicus
noelicus

Reputation: 15055

AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(true);

And then play the sound through the AudioManager.STREAM_SYSTEM stream.

When the sound's finished playing be sure to return the audio manager to its previous state or it'll stay on loudspeaker!!

Upvotes: 3

Related Questions