public class MediaPlayerLatch extends Object
Ordinarily a call to play new media returns immediately and the native media player attempts to open and start playing the media asynchronously. This can make it a little difficult for application code to know if the media successfully started or failed to start because of an error.
It is possible for application code to respond to media player events to determine whether the media started successfully or failed because of an error but this class serves as a convenient encapsulation of that functionality.
The strategy is simply to block the play call until a media player "playing" or "error" event is received.
Example usage:
mediaPlayer.prepareMedia(mrl, options); boolean definitelyStarted = new MediaPlayerLatch(mediaPlayer).play();The
DefaultMediaPlayer
uses this class for the "play and wait..." implementation, see
MediaPlayer.startMedia(String, String...)
.
Most applications are not expected to need this class and use the "start media" functionality on the media player instead.
Constructor and Description |
---|
MediaPlayerLatch(MediaPlayer mediaPlayer)
Create a new media player latch.
|
public MediaPlayerLatch(MediaPlayer mediaPlayer)
mediaPlayer
- media player instanceCopyright © 2009–2014 Caprica Software Limited. All rights reserved.