user1777060
user1777060

Reputation: 273

simultaneously using a headphone and speaker

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?

Upvotes: 3

Views: 9657

Answers (1)

Michael
Michael

Reputation: 58507

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

Upvotes: 4

Related Questions