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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009

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

Please use plain text.
Developer
hades_6
Posts: 178
Registered: ‎08-26-2009

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

code?

 

is the mp3 a local file or remote?

Please use plain text.
Developer
Aviator168
Posts: 705
Registered: ‎09-10-2009
My Carrier: Verizon

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

Do the playing on a separate thread.

Please use plain text.
Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009

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]

 

Please use plain text.
Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009

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?

 

Please use plain text.
Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009

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

Is your player logic working in other instances?

Please use plain text.
Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009

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. 

Please use plain text.
Developer
babygodzilla
Posts: 275
Registered: ‎03-10-2009

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

any ideas guys?

Please use plain text.