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 Contributor
Posts: 9
Registered: ‎12-14-2010
My Device: 9930
My Carrier: AT&T
Accepted Solution

BlackBerry Player implemenation stop() method not working with setLoopCount()

[ Edited ]

Has anyone else run into the following problem?

 

When using the BlackBerry implementation of javax.microedition.media.Player, I setLoopCount() with a number greater than 1.  I then start() the player.  Another thread calls stop() on the player, but it often does not stop playing (maybe 50% of the time).  Neither does it throw an exception.  I have verified using logs and a debugger that stop() is indeed getting called but not effective.

 

As far as I can tell, BlackBerry is failing to meet the Player API contract, which says the player should throw an exception if it cannot be stopped:

http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/media/Playe...


I see this behavior on OS 4.5 to 5.0 devices.  Generally simulators do not exhibit this behavior.

 

I have not yet proven whether it is specific to setLoopCount(), but I suspect so.

 

Am I missing something here?


Thanks for any help!

 

Will

Will
Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: BlackBerry Player implemenation stop() method not working with setLoopCount()

I suggest that you try without the setLoopCount().

I have been using the player lately but never had the problem you described and I am also testing on devices.I just haven't used setLoopCount()

After you stop the player can you check its state and see what it shows? Also these debug logs - are they your prtints ot internal bb logs? You can also try to attach PlayerListener and see what happens.Also verify that your threads are synchronized ans you access the Player object correctly.

----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
New Contributor
Posts: 9
Registered: ‎12-14-2010
My Device: 9930
My Carrier: AT&T

Re: BlackBerry Player implemenation stop() method not working with setLoopCount()

Thanks for the suggestion, dx22.  I may implement my own looping mechanism instead.  I have not yet examined the state when stop() failed but that would be helpful.  Perhaps it alternates between prefetched and started each repeat, and I'm unfortunately hitting the prefetched frequently.  Of course it should throw an exception in that case, but I'm repeating myself.  =)

Will
Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: BlackBerry Player implemenation stop() method not working with setLoopCount()

Well here http://www.blackberry.com/developers/docs/5.0.0api/ in the doc for the Player class there is a diagram explaining the player states well. So from that it seems ok that the player is in prefetched state after calling stop().

When you call stop() it goes back in prefetched state but can be started again. If you want to stop it completely try calling close() or deallocate().

 

Are you using custom mechanisms for providing data to tha player like custom implementation of Datasource, SourceStream or you just provide locator url for some media?

 

 

----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Highlighted
New Contributor
Posts: 9
Registered: ‎12-14-2010
My Device: 9930
My Carrier: AT&T

Re: BlackBerry Player implemenation stop() method not working with setLoopCount()

Thanks again.  I hadn't gotten to trying close() yet, but I did today and fortunately it works as I would have hoped.  And in this case close() is okay because I don't need to reuse the player.  So in summary, it looks like anyone else running into this situation can resolve it in at least the following ways:

1) Use close() instead of stop() if you can, or

2) Implement the looping mechanism yourself, as the behavior of stop() with setLoopCount() is nondeterministic.

 

It looks like #2 is indeed possible because the END_OF_MEDIA event correctly occurs at the end of play, so you can restart play each time that is reached.  But I did not try to implement this approach.

Will