uk.co.caprica.vlcj.player
Class MediaPlayerLatch
java.lang.Object
uk.co.caprica.vlcj.player.MediaPlayerLatch
public class MediaPlayerLatch
- extends java.lang.Object
This class implements a strategy for handling multiple player instances.
A strategy is required since there are threading issues in the native
libraries that are exposed as races when repeated calls to play() are made.
The strategy is simply to block the play call until a media player playing
event is received.
This has limitations in that if an error occurs (e.g. file not found) then
it will block forever since no playing event will be received nor in fact
will any error event.
For this reason it is possible to specify a timeout - if the timeout expires
before a playing event is received then the play method will return (the
return value will be false
. It is possible that the media will
still actually start playing even if false
is returned.
Example usage:
mediaPlayer.prepareMedia(mrl, options);
new MediaPlayerLatch(mediaPlayer).play();
Or:
mediaPlayer.prepareMedia(mrl, options);
MediaPlayerLatch playerLatch = new MediaPlayerLatch(mediaPlayer);
playerLatch.setTimeout(3, TimeUnit.SECONDS);
boolean maybeStarted = playerLatch.play();
This class is experimental and is subject to change/removal.
Method Summary |
boolean |
play()
|
void |
setTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MediaPlayerLatch
public MediaPlayerLatch(MediaPlayer mediaPlayer)
setTimeout
public void setTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
play
public boolean play()