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

Adobe AIR Development

Reply
Contributor
Posts: 29
Registered: ‎12-07-2010
My Device: PlayBook
My Carrier: None

Event fired by play/pause button on top of device

Hi,

Does anyone know if any event is fired from the buttons on the top of the device?

I have a media player app, that I would like to be controlled by these buttons as well as the software controls within the app, and after searching the api ref I can find nothing, but I am prob missing something...

Shane
/**********************************************************************/

Playbook apps:
LPlayer

Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Event fired by play/pause button on top of device

+1 - I would also love to know if I can hook these into my media app...

 

 

Highlighted
Developer
Posts: 137
Registered: ‎10-26-2010
My Device: Bold 9900 + PlayBook
My Carrier: Rogers

Re: Event fired by play/pause button on top of device

[ Edited ]

I haven't tested this on a real device, but I'm pretty sure that what you want is MediaServiceConnection. Anytime you're playing media you should be using it, it has events for media controls which I believe will include both the top buttons and from the system tray icon. It also gives you the ability to report metadata so that the system tray media player control pop-up can display currently playing info.

--------
Taylor Byrnes
Contributor
Posts: 29
Registered: ‎12-07-2010
My Device: PlayBook
My Carrier: None

Re: Event fired by play/pause button on top of device

yes it looks like the MediaServiceRequestEvent.TRACK_PAUSE / TRACK_PLAY are the events I am looking for, thanks for pointing me in the right direction....Smiley Happy
/**********************************************************************/

Playbook apps:
LPlayer

Developer
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: Event fired by play/pause button on top of device

Doesn't it just generate a keyboard event with keycode Keyboard.PLAY / Keyboard.PAUSE? 

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Contributor
Posts: 29
Registered: ‎12-07-2010
My Device: PlayBook
My Carrier: None

Re: Event fired by play/pause button on top of device

[ Edited ]

OK It would appear that none of these are correct. I finally had a chance to get some debugging done on the device tonight and when instantiating the MediaServiceConnection and connecting the events aren't fired and none of the keyboard events seem to work on those buttons, anyone else have any ideas?

/**********************************************************************/

Playbook apps:
LPlayer

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Event fired by play/pause button on top of device

Possibly you're just doing it wrong. Maybe post some sample code showing what you've been trying. Also, if you no longer consider taylortbb's answer to solve your problem, you can choose from the options menu on that post to unselected it as the Solution, for now (to avoid confusing others, until his solution can be confirmed).

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 29
Registered: ‎12-07-2010
My Device: PlayBook
My Carrier: None

Re: Event fired by play/pause button on top of device

[ Edited ]

OK I am doing this:

 

 

private function initMSC():void
{
	var mc:MediaServiceConnection = new MediaServiceConnection();
	mc.addEventListener(MediaServiceRequestEvent.TRACK_PAUSE, pauseClicked);
	mc.addEventListener(MediaServiceRequestEvent.TRACK_PLAY, playClicked);
	mc.connect();
}

private function pauseClicked(e:MediaServiceRequestEvent):void
{
	//pause music
}
		
private function playClicked(e:MediaServiceRequestEvent):void
{
	//play music
}

 

 

/**********************************************************************/

Playbook apps:
LPlayer

Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Event fired by play/pause button on top of device

I wouldn't be surprised if there's some undocumented permission we need to specify...
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Event fired by play/pause button on top of device

@shawnblais, or even a documented permission.  (Well, not documented exactly when they're required, but there is that list... play_audio maybe?)

 

As for the MediaServiceConnection, I'm guessing more is needed to set things up.  Wouldn't you expect to send some info with sendMetadata() first?  Maybe add a check for hasAudioService() and/or canSendData()?  Possibly also requestAudioService()?

 

I could picture the sequence being add listeners, connect(), get CONNECT event, requestAudioService(), get ACCESS_CHANGE event, do something with the send data stuff, and so on.

 

To troubleshoot such things, I always suggest adding listeners for all the events listed, with at least trace() calls. Then start experimenting and gradually add other stuff.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!