且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何静音音频耳机,但让它以编程扬声器上播放?

更新时间:2022-10-15 16:29:18

  AudioManager上午=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(真正的);
 

,然后播放通过 AudioManager.STREAM_SYSTEM 流的声音。

在声音的成品播放,请务必将音频管理器返回到它的previous状态,或者它会留在扬声器!!

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?

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!!