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
New Developer
brent_glad
Posts: 66
Registered: ‎11-23-2009
My Device: Not Specified

Having a player reconnect after switching network interfaces

Hello,

 

I am making an audio player and I want it to reconnect automatically if the user switches from Wi-Fi to 3G/EDGE.

 

When there is 3G/EDGE and Wi-Fi available, and then Wi-Fi disconnects, the Listener reports that buffering starts AND the player's state is still "started." It then hangs for 2 minutes (this is very consistent, btw), then the Player reports an ERROR to the Listener.

 

Then my code tells it to start the player again after an ERROR.

 

The problem is is that it remains in that state where it attempts to buffer while still being in STARTED state for about TWO minutes. THEN it fails and reports an ERROR...why does it take so long to report an error?

 

I want it to stop and reconnect as soon as it loses its interface. How can I do that?

Please use plain text.
New Developer
brent_glad
Posts: 66
Registered: ‎11-23-2009
My Device: Not Specified

Re: Having a player reconnect after switching network interfaces

I figured it out. It appears that when the Player loses its connection, and it goes into that STARTED and BUFFERING STARTED phase, you can have a line in your Listener:

 

 

if (s == PlayerListener.BUFFERING_STARTED && _player.getState() == Player.STARTED)

 

 

Then in the { } you can have it try to start again.

 

This works great. Except for one problem that's been bugging me for a long time:

 

If I try to start and stop the play stream too many times in succession, it gets into this delayed mode and won't connect for a VERY long time.

 

It is fine if I connect about every minute or so, but I'm afraid this makes it hard to demo the app to people...

Please use plain text.