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
babygodzilla
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

stuck in a rut: cannot play music on first screen

Hello,

 

I have a little confusing situation here. This is the general flow of my application:

 

1. Device loads app

2. App calls App() (constructor)

3. App calls new MyScreen()

4. App enters EventDispatcher

 

Now on MyScreen() I would like to play an mp3 as background music, but I cannot do so presumably because I have not entered the Event Dispatcher. I'm getting a Runtime Exception and some push Modal Screen error or something like that. I tried doing getApplication().invokeLater() in MyScreen() but getApplication() returns null, again presumably because I have not entered event dispatcher. 

 

Quite confused on what I'm supposed to do here. There's nothing much in MyScreen(), just a label and a couple of buttons. 

 

Suggestions? Advice?

 

Thanks a lot

Developer
hades_6
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: stuck in a rut: cannot play music on first screen

code?

 

is the mp3 a local file or remote?

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

Re: stuck in a rut: cannot play music on first screen

Do the playing on a separate thread.

Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: stuck in a rut: cannot play music on first screen

[ Edited ]

thanks for the quick reply. not much code here. UiApplication class: [code]

public static void main(String[] args) {
 MyGame game = new MyGame(); 
game.enterEventDispatcher(); 
} 
public MyGame() { pushScreen(new Menu()); } 

 

[/code] Menu class: [code]

Menu() { 

//add buttons etc etc 

playMusic() //play music loads resources and calls Player.start() 
} 

 

[/code]

 

Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: stuck in a rut: cannot play music on first screen

 


Aviator168 wrote:

Do the playing on a separate thread.


 

I thought about this, but not really sure who should start the thread. If I start the thread in Menu() the app still hasn't entered event dispatcher, right?

 

Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: stuck in a rut: cannot play music on first screen

Is your player logic working in other instances?

Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: stuck in a rut: cannot play music on first screen

yes it is. i have used it in the next screen that is pushed after user presses on a button in the Menu class, and it works fine. 

Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: stuck in a rut: cannot play music on first screen

any ideas guys?