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
Contributor
eggshapedfred
Posts: 16
Registered: ‎01-08-2013
My Device: Developer
My Carrier: N/A
Accepted Solution

Determining if music is playing in another app

Hello,

 

I am currently porting an iOS game to the BB10 platform. One minor feature supported we supported with the iOS version is that if the user was currently playing some music through the iPod app when they launched our game, we automatically disabled the music in the game to allow their music to continue playing.

 

I would like to recreate this functionality on BB10 but cannot seem to find a reliable way of simply determining if any music is currently playing in another app. I can stop any playing music simply by calling mediacontroller_stop() when our game launches, which is at least better than having the external app and our game playing music at the same time, but this isn't a particularly 'nice' solution and I'd like to improve it if possible, so I was wondering if anyone had any suggestions for how I might do this?

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

Re: Determining if music is playing in another app

Would this help?

 

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_re...

 

or this:

 

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.audiomanager.lib_ref/topic/manual/...

 

Or you could even snoop around the PPS objects to see if there's a flag you could use.

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
Please use plain text.
Contributor
eggshapedfred
Posts: 16
Registered: ‎01-08-2013
My Device: Developer
My Carrier: N/A

Re: Determining if music is playing in another app

Hello, thanks for the response.

 

Yes, I thought the mediaplayer would be just what I needed but although the library functionality is described as allowing media players to work together I couldn't find anything that would allow me to simply query whether any other music was playing.

 

Regarding the audio device library, I may be misunderstanding the documentation but my impression is that it is really for querying the status of audio devices rather than the state of any media that may or may not be playing on them.

 

In both cases there may be another way of using the library to get the results I want but unfortunately so far I've not been able to find any information that suggests how.

Please use plain text.
Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Determining if music is playing in another app

[ Edited ]

As far as I understood the docs, MediaPlayer provides service for playing content. In your case, you need something to control/manage content that is already playing/in use etc. This should help you http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_re...

Please use plain text.
Contributor
eggshapedfred
Posts: 16
Registered: ‎01-08-2013
My Device: Developer
My Carrier: N/A

Re: Determining if music is playing in another app

[ Edited ]

Ah okay, yes, with some playing around I eventually got the information from the mediacontroller. It seems that if music is already playing, when your app launches the mediacontroller sends a MEDIACONTROLLER_STATE event with the state MEDIASTATE_PLAYING. By setting up a listener for this event I was able to grab it and disable our music.

 

For anyone else trying to solve a similar problem, the pertinent code is as follows:

 

#include <bps/mediacontroller.h>
int main(int argc, char *argv[])
{
/* Set up listener */ mediacontroller_request_events(0);

/* Basic application loop */ while (!exit_application) { //Request and process all available BPS events bps_event_t *event = NULL; for(;;) { if(event) { if(domain == mediacontroller_get_domain()) { const int code=bps_event_get_code(event); if(code == MEDIACONTROLLER_STATE) { const media_state_t state=(media_state_t)mediacontroller_event_get_state(event); switch(state) { case MEDIA_STATE_PLAYING: { /* Disable in-game music */ break; } case MEDIA_STATE_UNRECOGNIZED: case MEDIA_STATE_STOPPED: case MEDIA_STATE_PAUSED: case MEDIA_STATE_TRACK_CHANGE: { break; }
} } } }
}

 

Obviously this could also be used for reacting to other state changes if required too.

 

Cheers for the assistance folks!

Please use plain text.