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
New Contributor
Posts: 7
Registered: ‎03-14-2013
My Device: Z10 STL100-3
My Carrier: Numerous

Capture headphone button and physical button possible?

Is it possible to caputre the headphone jack's play/pause button as well as the volume rocker buttons on the side of the Z10?

 

I have only seen the music app be able to accept the pause/play signal from the headphone as well as the volume rockers.

 

I have yet to see a third party app that captures these signals successfully.

 

Thanks.

Developer
Posts: 1,185
Registered: ‎03-24-2011
My Device: Passport/Z30//Q10/ Z10 / 9900 / PlayBook / 9700 / 8900
My Carrier: ATT

Re: Capture headphone button and physical button possible?

What do you mean by caputre the headphone jacks play/pause?
I am not understanding the questions.
New Contributor
Posts: 7
Registered: ‎03-14-2013
My Device: Z10 STL100-3
My Carrier: Numerous

Re: Capture headphone button and physical button possible?

[ Edited ]

For example, I will be listening to an audiobook third party app while I'm grocery shopping and I bump into a friend. I want to pause the audiobook, so I click on the headphone pause/play button but nothing happens.

 

I have to take the phone out of my pocket, swipe it awake, and touch the pause icon. I want to make it that you can pause/play without having to do that using the headphone or at least the volume rocker buttons.

New Contributor
Posts: 7
Registered: ‎03-14-2013
My Device: Z10 STL100-3
My Carrier: Numerous

Re: Capture headphone button and physical button possible?

Just an update: found an app that captures the pause/play headphone input(nobex). Basically apps ported from android doesn't work with the headphone for now.

So I know it's possible, now I just need lead on where to find the function. Anyone able to point me in the right area?
Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Capture headphone button and physical button possible?

[ Edited ]

Well, these functions (part of BPS library) seem to be for the physical buttons and not entirely sure if it's tied in with headphone controls as well..

https://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_r...

 

--Edit--

Tested it out on the Simulator with the Controller... Seems to work..  Unfortunately, cannot test headphones heh..

New Contributor
Posts: 7
Registered: ‎03-14-2013
My Device: Z10 STL100-3
My Carrier: Numerous

Re: Capture headphone button and physical button possible?

Thanks for the reply.

 

I can't believe I just didn't search for "button" LOL. I search for headphone, pause/play, volume rocker... everything but "button". D-uh!

 

So I took a look at the link you posted, from the looks of it, I have to start using C++ code if I want to listen for the  buttons event? I was hoping to avoid C++ if possible.

Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Capture headphone button and physical button possible?

[ Edited ]

Well, yes you'll have to get your foot dirty... So to speak...

 

Just some of the essential stuff you'll need:

 

#include <bps/button.h>
#include <bps/navigator.h>
#include <bps/bps.h>
#include <bps/event.h> //Initialize BlackBerry Platform Services (BPS) library. bps_initialize(); // Make the request to listen to Button events. if (BPS_SUCCESS != button_request_events(0)) { fprintf(stderr, "Request for button events failed.\n"); } // Loop for handling BPS events and any other things you may need. while (!exit_application) { //Request and process all available BPS events bps_event_t *event = NULL; for(;;) {
// Get an event that happened and check that
// there were no errors.. if (BPS_SUCCESS != bps_get_event(&event, 0)) { fprintf(stderr, "bps_get_event failed\n"); break; }
// Check which domain the event came from and act
// accordingly.. if (event) { int domain = bps_event_get_domain(event);
if (domain == button_get_domain()) {
// Call a function or two here to handle the Button event...
fprintf(stderr, "Button: %d\n", button_event_get_button(event));
} else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } else { break; } } }

// Stop requesting Button events
button_stop_events(0);

// Shutdown the BPS library
bps_shutdown();

 

Btw, this is not a complete application...