11-01-2013 03:32 PM
When I play a sound file using MediaPlayer it goes out the device speakers instead of the Bluetooth headset. I have other sounds generated by my app going over BT so I know the device is paired and working fine. How do I force the output from MediaPlayer to go over Bluetooth? Here's my code with error checking removed (I get no errors):
audio_manager_get_handle(AUDIO_TYPE_SOUND_EFFECT, 0, true, &audioManager);
audio_manager_set_handle_routing_conditions(audioManager, SETTINGS_RESET_ON_DEVICE_DISCONNECTION | SETTINGS_RESET_ON_DEVICE_CONNECTION);
11-05-2013 11:34 AM
I've found that calling the following and changing the above code to also use AUDIO_TYPE_VIDEO_CHAT seems to sort of work in some cases. The ringing isn't as loud when using
AUDIO_DEVICE_SPEAKER so I suspect it is actually still using
AUDIO_DEVICE_HANDSET but I can now get it to ring in the Bluetooth device. If I instead use
AUDIO_TYPE_SOUND_EFFECT the Bluetooth doesn't ring but when ringing on the device it is much louder. What is the logic behind this behaviour? Should I change the AUDIO_TYPE_XXX depending on the device I want to ring? This seems very strange!
audio_manager_set_handle_type(m_audioManager, AUDIO_TYPE_VIDEO_CHAT, output, input);
11-06-2013 07:07 PM
Further testing shows my code only works on OS 10.2 but not on OS 10.1 when a Bluetooth device is the desired output. The output seems to always go to the loudspeaker in 10.1. Here is my current code...
audio_manager_get_handle(AUDIO_TYPE_RINGTONE, 0, true, &m_audioManager);
audio_manager_audio_type_t type = AUDIO_TYPE_RINGTONE;
audio_manager_device_t input = AUDIO_DEVICE_DEFAULT;
audio_manager_device_t output = AUDIO_DEVICE_DEFAULT;
output = AUDIO_DEVICE_HEADSET;
output = AUDIO_DEVICE_SPEAKER;
// this only works for OS 10.2?
output = AUDIO_DEVICE_BT_SCO;
type = AUDIO_TYPE_VIDEO_CHAT; // otherwise rings loudspeaker for BT case?
output = AUDIO_DEVICE_HANDSET;
audio_manager_set_handle_type(m_audioManager, type, output, input);
m_mediaPlayer.setRepeatMode(looping ? RepeatMode::Track : RepeatMode::None);
11-19-2013 04:02 PM
Sorry for the delay; we are looking into this now. The default MediaPlayer (i.e. without having to change things through AudioManager handle) should allow playback through BT device if profile used is A2DP. Is it possible for you to verify that? The BT SCO is not really meant for multimedia apps - that's the handsfree profile. On that note, it makes sense why the audio type would need to be set to voice chat, if the device type is BT_SCO.
Also, can you confirm what "ringing" you are referring to in your posts? Are you just referring to the sound coming out of the speakers of the connected BD device (or when it is through the phone). You are not referring to the call ringing correct? (because that is also a use case; hence, just confirming).
Application Development Consultant | Developer Relations
11-20-2013 06:38 PM - edited 11-20-2013 06:41 PM
Since we are a VoIP application we are using BT_SCO devices. We use the MediaPlayer to play the ring tone in the device and then once the call is established we use the PCM calls such as audio_manager_snd_pcm_open_name() with the audio type of AUDIO_TYPE_VIDEO_CHAT. I am using the audio manager handle returned by this call to pass into
audio_manager_set_handle_type() when I want to route the audio between AUDIO_DEVICE_BT_SCO and AUDIO_DEVICE_SPEAKER.
It looks like we now have the MediaPlayer aspect working correctly in OS 10.2 so I'm not so worried about the older OS case, but the call audio itself is not being switched correctly between the device speaker and the BT speaker. It seems I have the reverse problem for call audio in that for some devices the call audio ALWAYS goes through the BT device even if I route it to the loudspeaker! The calls are completing without errors so I suspect there is something in the routing that is of higher priority or something so it's ignoring what I'm setting?
This latter problem I posted here where you can see my code: