Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
dlacerte
Posts: 68
Registered: ‎03-12-2013
My Device: BB Z10
My Carrier: Rogers

How to use MediaPlayer over Bluetooth?

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);

 

m_mediaPlayer.setAudioManagerHandle(audioManager);

 

m_mediaPlayer.setSourceUrl(url);

 

m_mediaPlayer.setRepeatMode(RepeatMode::Track);

 

m_mediaPlayer.play();

 

Please use plain text.
Regular Contributor
dlacerte
Posts: 68
Registered: ‎03-12-2013
My Device: BB Z10
My Carrier: Rogers

Re: How to use MediaPlayer over Bluetooth?

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);

Please use plain text.
Regular Contributor
dlacerte
Posts: 68
Registered: ‎03-12-2013
My Device: BB Z10
My Carrier: Rogers

Re: How to use MediaPlayer over Bluetooth?

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);

 

m_mediaPlayer.setAudioManagerHandle(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;

 

switch (device)

{

case AD_Earphone:

  output = AUDIO_DEVICE_HEADSET;

  break;

 

case AD_LoudSpeaker:

  output = AUDIO_DEVICE_SPEAKER;

  break;

 

case AD_Bluetooth:

  // this only works for OS 10.2?

  output = AUDIO_DEVICE_BT_SCO;

  type = AUDIO_TYPE_VIDEO_CHAT; // otherwise rings loudspeaker for BT case?

break;

 

case AD_Handset:

  output = AUDIO_DEVICE_HANDSET;

  break;

 

default:

  ASSERT(0);

  break;

}

 

audio_manager_set_handle_type(m_audioManager, type, output, input);

 

m_mediaPlayer.setSourceUrl(QUrl(fileName));

 

m_mediaPlayer.setRepeatMode(looping ? RepeatMode::Track : RepeatMode::None);

 

m_mediaPlayer.play();

 

Please use plain text.
BlackBerry Development Advisor (Retired)
s_rashid
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: How to use MediaPlayer over Bluetooth?

Hi @dlacerte,

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).

Thanks,
Rashid

Application Development Consultant | Developer Relations

BlackBerry
@surashid



Please use plain text.
Regular Contributor
dlacerte
Posts: 68
Registered: ‎03-12-2013
My Device: BB Z10
My Carrier: Rogers

Re: How to use MediaPlayer over Bluetooth?

[ Edited ]

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:

http://supportforums.blackberry.com/t5/Native-Development/How-to-direct-audio-AWAY-from-Bluetooth-de...

Please use plain text.