Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simultaneously using a headphone and speaker

Tags:

android

audio

I'd like to use the speaker for audio output while simultaneously using the headphone jack for a different audio output/input. Is this possible?

like image 469
user1777060 Avatar asked Dec 19 '25 23:12

user1777060


1 Answers

It's possible to do on some devices (I've verified that it works on a Sony XPeria P), but I don't think you can count on it to work on all devices.

What you'd do is force MUSIC streams to route to the loudspeaker:

Class audioSystemClass = Class.forName("android.media.AudioSystem");
Method setForceUse = audioSystemClass.getMethod("setForceUse", int.class, int.class);
// First 1 == FOR_MEDIA, second 1 == FORCE_SPEAKER. To go back to the default
// behavior, use FORCE_NONE (0).
setForceUse.invoke(null, 1, 1);

Then you use the MUSIC stream for anything you want routed to the loudspeaker, and the VOICE_CALL stream for anything you want routed to the headset/headphones.

See my answer for Playing sound over speakers while playing music through headphones

like image 121
Michael Avatar answered Dec 22 '25 12:12

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!