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

Java Development

Reply
Developer
uttamtts
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
Accepted Solution

Playing music fromBackground Application

Hello all,

I am working on Alarm application. I a want to play music from background application. But i am getting an issue implementing that. when more than one alarm is set for same time. The player is not playing music. How to overcome on it.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Playing music fromBackground Application

What problem are you seeing?  Can you give us the detail please.

Developer
uttamtts
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone

Re: Playing music fromBackground Application

[ Edited ]

Actually i am using a screen to show a user and in that class's constructor i am playing the music file which i get from the database. I have used

ui.pushGlobalScreen(new AlarmScreen(), 1, UiEngine.GLOBAL_QUEUE);

and in the constructor of that class i am initializing the player. But this class is pushed more than one time when there is more than one alarm is set by user for that specific time. so my application crashes on mediaPlayer.prefetch(); method. i dont understand how to solve the issue.

Developer
uttamtts
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone

Re: Playing music fromBackground Application

please help me to solve this issue .
Developer
uttamtts
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone

Re: Playing music fromBackground Application

@pe
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Playing music fromBackground Application

In a similar situation I used RuntimeStore to make sure that I only ever had one Media Player running at one time (I put the player in there, and then if there was one there already, I stopped it before starting my new player.  Actually my memory is failing, I might have changed the media that was being played.  Either should work.  I suspect a similar approach will work for you too. 

Developer
Aviator168
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930

Re: Playing music fromBackground Application


uttamtts wrote:

Hello all,

I am working on Alarm application. I a want to play music from background application. But i am getting an issue implementing that. when more than one alarm is set for same time. The player is not playing music. How to overcome on it.



You cannot have more than ONE player active at any give time in many BBs. Some BBs, you can have at most 2.

Developer
uttamtts
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone

Re: Playing music fromBackground Application

Thank you for reply @Peter_Strange can you elaborate it more. How does this work .
Developer
uttamtts
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone

Re: Playing music fromBackground Application

[ Edited ]

yeah that i know but how can i be sure that there is only one Player active . I dont have any control over the pushGlobalScreen();  it just pushing the screen one after other.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Playing music fromBackground Application

As noted, the issue is multiple players.

 

Basically the 'solution' I outlined uses RuntimeStore as a Repository for the Player, and so, if you create a new Global Screen, you can check to see if there is already a Player active and take the appropriate action.  In summary, you are using the Player as a Singleton by getting it from and putting it into RuntimeStore.

 

I'm not sure what else needs to be elaborated.  Please ask a specific question for more detail.

 

Here is a KB article that describes using RuntimeStore to manage a Singleton:

http://supportforums.blackberry.com/t5/Java-Development/Create-a-singleton-using-the-RuntimeStore/ta...