03-10-2011 04:21 PM - edited 03-10-2011 04:23 PM
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:
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!
Solved! Go to Solution.
03-10-2011 05:13 PM
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.
03-10-2011 05:31 PM
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. =)
03-11-2011 03:36 AM
Well here http://www.blackberry.com/developers/docs/5.0.0api
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?
03-11-2011 05:55 PM
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.