In Android, is there any way to route the audio to A2DP using “MODE_IN_COMMUNICATION”?

浪子不回头ぞ 提交于 2021-02-08 10:27:24

问题


If I set AudioManager mode to MODE_IN_COMMUNICATION, and set the Media Player stream to STREAM_VOICE_CALL, I can route the audio to the speakerphone or the internal handset speaker just fine. And if it's routed to the internal speaker, and a wired headset is plugged int, it automatically routes to it. However, I can't figure out a way to route the audio to an A2DP headset (without changing the audio mode to MODE_NORMAL, or the stream to STREAM_MUSIC). My problem is that using MODE_NORMAL and STREAM_VOICE_CALL causes problems on some devices, and using STREAM_MUSIC is a problem if there is already music playing in the background, then my app "mixes" with that background music.

So, I was hoping that there was a way to force the audio to the A2DP headset using the MODE_IN_COMMUNICATION and STREAM_VOICE_CALL combination. Is that possible?


回答1:


Perhaps it works on some devices, but if you care about compatibility across the majority of devices then the answer is "No".

When the phone state is MODE_IN_CALL or MODE_IN_COMMUNICATION all streams will typically follow the PHONE routing strategy. This means that routing to A2DP will not be allowed since:

1) A2DP doesn't support two-way voice anyway.

2) If your BT accessory supports the Hands-free profile it will use a SCO link for the voice audio, and the ACL channel used for A2DP should be closed to avoid interference between the two.



来源:https://stackoverflow.com/questions/16432768/in-android-is-there-any-way-to-route-the-audio-to-a2dp-using-mode-in-communica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!