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
Developer
Enaud
Posts: 57
Registered: ‎02-08-2013
My Device: z10
My Carrier: rogers

Interfacing with Hardware Controls

I'd like to acheive two things I was hoping to get help from one of you awesome developers:

- Have my app skip to the next (or previous) track using the "Music shortcuts" triggered by a long press on the volume buttons. When I enable the "Music shortcuts" in the settings it only seems to work with the music and video player. How to I interface with these long press events?

- I also want to get notification of more advanced audio control systems (like BT remotes, buttons on headphones) to control the media. Does anyone know how to do this? I implemented slots for every signal the NowPlayingConnection offers but this doesn't seem to be enough.

 

Thanks!

Eric

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

Re: Interfacing with Hardware Controls

Hi @Enaud,

For listening on to "next" and "previous" track key presses from the device, have you already tried listening on the "next" and "previous" signals emitted from the NowPlayingConnection class?

"next" signal: https://developer.blackberry.com/native/reference/cascades/bb__multimedia__nowplayingconnection.html...

"previous" signal: https://developer.blackberry.com/native/reference/cascades/bb__multimedia__nowplayingconnection.html...

 

These should be emitted accordingly.

With regards to your question about the advanced media controls from BT devices or headphones with remote controls - we are confirming the state now. I will update the thread here as soon as I find something.

Cheers,
Rashid

Application Development Consultant Developer Relations

BlackBerry
@surashid



Please use plain text.
Developer
Enaud
Posts: 57
Registered: ‎02-08-2013
My Device: z10
My Carrier: rogers

Re: Interfacing with Hardware Controls

Hello Rashid,

 

I've connected to every signal in the NowPlayingConnection class, it add nice functionality but not what I was looking for - it doesn't respond to the long volume Up/Down press where the media play does (when it's enabled in the volume settings).

 

I'd like to find a way of enabling these signal to my app.

 

Eric

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

Re: Interfacing with Hardware Controls

Hi Eric,

This sounds bizarre. Under the following two conditions, you app should be getting these *next* and *previous* signals on a long press of the volume up/down buttons:

 

i) App *acquired* the NowPlayingConnection
ii) The Settings app on BB10 has the music shortcuts enabled

 

If the core BB10 music player app can receive the next/previous track short cuts, so should the other apps, as they are using the same code.

Can you please confirm these conditions? (special note that your app's MediaPlayer instance is the most recent one which acquired the NowPlayingConnection)

Thanks,
Rashid

Please use plain text.
Developer
Enaud
Posts: 57
Registered: ‎02-08-2013
My Device: z10
My Carrier: rogers

Re: Interfacing with Hardware Controls

Hello Rashid,

 

My app is several thousand lines of code so here's the relvant exerpts:

mediaPlayer = new MediaPlayer();
...
npConnection = new NowPlayingConnection();
connect(npConnection, SIGNAL(next()), this, SLOT(onNowPlayingNext()));
connect(npConnection, SIGNAL(previous()), this, SLOT(onNowPlayingPrevious()));

...
void app::onNowPlayingPrevious()
{
	 log("%s:%d\n", __FUNCTION__, __LINE__);
	 onSkipBack(); // 
}

void bepod::onNowPlayingNext()
{
	 log("%s:%d\n", __FUNCTION__, __LINE__);
	 onSkipForward();
}

 void bepod::onNowPlayingAcquired()
 {
     log("%s:%d\n", __FUNCTION__, __LINE__);
 }

 At run time, when the user asks the app to play something this code gets executed:

if (!npConnection->isAcquired()) {
   int error = (int) npConnection->acquire();
   if (error != (int) MediaError::None) {
      toast("Could not get control of audio device");
      log("%s:%d NowPlayingConnection could not be acquired error=%d\n", __FUNCTION__, __LINE__, error);
   }
   } else {
      log("%s:%d NowPlayingConnection is Already Acquired\n", __FUNCTION__, __LINE__);
   }

   bb::multimedia::MediaError::Type mediaError = mediaPlayer->play();
   if (mediaError != bb::multimedia::MediaError::None) {
      log("%s:%d - Trying to play ep_id=%d failed with MediaError=%d\n", __FUNCTION__, __LINE__, ep_id, (int )mediaError);
      toast("Could not play file, there's something wrong with the media player...");
      return false;
   } 

 I can see the 'acquired' signal call the onNowPlayingAcquired() slot in my logs.

 

Now when I press the volume up or down for more than 600ms the Now Playing overlay appears, and the volume gets adjusted instead of skiping to the next or previous track. Not at all like how the stock media player operates.

 

Do I need to connect the slots _after_ the connection is acquired?

 

Thanks,

Eric

 

Please use plain text.