0

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?

user496854
  • 6,461
  • 10
  • 47
  • 84

1 Answers1

0

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.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • actually, STREAM_VOICE_CALL and MODE_NORMAL work in virtually all devices. I understand what you're saying, but there are some devices (and ROMs) that won't route any audio at all when using STREAM_VOICE_CALL (no speaker phone, or anything). But any device that allows to use STREAM_VOICE_CALL for speaker, will also stream it over A2DP. – user496854 May 09 '13 at 15:39
  • _"actually, STREAM_VOICE_CALL and MODE_NORMAL work in virtually all devices"_ Sure, but my answer was for your question regarding `MODE_IN_COMMUNICATION`. _"any device that allows to use STREAM_VOICE_CALL for speaker, will also stream it over A2DP"_ Not while in a call (i.e. when the phone state is `MODE_IN_CALL` / `MODE_IN_COMMUNICATION`). – Michael May 09 '13 at 15:49
  • That's why I didn't mention "MODE_IN_CALL" in the question. Using MODE_NORMAL / STREAM_VOICE_CALL gets the audio to play over both internal speaked or speakerphone, and if a wired, usb or A2DP headset is connected, the audio automatically gets routed to them. That's why that combination is so useful. But some devices just don't allow hijacking of STREAM_VOICE_CALL, so I thought MODE_IN_COMMUNICATION would work the same way (but it looks like it doesn't) – user496854 May 09 '13 at 15:53
  • Sounds to me like the `MUSIC` stream is what you want. As for your app's audio getting mixed with other audio, that's just the way it works. Many devices simply do not make any distinction between different streams at the lower levels (at one point or another they get mixed into one), making it pretty much impossible to route one stream type to one output (e.g. the speaker), and another stream type someplace else (e.g. A2DP). There are exceptions to this, like the U8500 platform from ST-E (used e.g. in the XPeria P and XPeria U, and I think the Galaxy S3 Mini). – Michael May 09 '13 at 16:16
  • @Michael Is this still the case? If so, are custom routing strategies possible? Another possible workaround would be to request playback focus through interaction with the stereo via something like [this](https://www.youtube.com/watch?v=6HKOW2wXo8g), do you know where I could look to see about that? I'm not trying to do two-way voice, just interrupt FM radio with stereo music from the phone. – Ben Gardner Apr 02 '20 at 02:40