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
Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

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

Nice call Peter, I always have a tough time actually tracking down the docs for each SDK. I'll give that a shot. play_audio is not required to actually play audio, so it seems that it might fit the bill for the audio controls...

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

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

[ Edited ]

Ok, I managed to get this working!

 

Here is the process:

 

--------

 

var mediaService:MediaServiceConnection = new MediaServiceConnection();

mediaService.connect();

mediaService.requestAudioService();

mediaService.addEventListener(MediaServiceRequestEvent.TRACK_PAUSE, function(){ trace("Pause!"); });

 

--------

That's all you really need to do! You now get a pause event anytime the button is clicked From what I'm seeing PLAY/NEXT/PREV are never dispatched.

If you want to still be able to compile on the desktop, just throw those 4 lines in a function, and then you can do:
if(Capabilities.os.indexOf("PlayBook") > -1){
      addPauseListener();
}

Note: After connection you'll get connectionSuccess event, after requesting the audioService, you'll get an accessChanged event. I don't see any issues just attaching your PAUSE handler upfront though...and calling requestAudio immediately after connect() seems to work fine.

 

Highlighted
Contributor
Posts: 32
Registered: ‎02-02-2011
My Device: Playbook
My Carrier: none

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

this didn't work for me.  i have a timer app with an alarm. i have the MediaServiceRequestEvent.TRACK_PAUSE triggering a stopSound function. with this code in my app, the play/pause button still has its default action. it toggles muting for the Playbook on and off instead of simply stopping the audio. anyone else getting this to work?

--------------------------------------
Dirty Kitchen Cooking Timer
http://appworld.blackberry.com/webstore/content/37403