simultaneously using a headphone and speaker

前端 未结 1 1910
醉梦人生
醉梦人生 2020-12-03 16:36

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?

相关标签:
1条回答
  • 2020-12-03 17:15

    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

    0 讨论(0)
提交回复
热议问题