X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bindings%2Fjava%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fvideolan%2Fjvlc%2FMediaListPlayer.java;h=032008e4557dcc6db5c2036b7cc19f240a460b26;hb=de94406f0097da88e57f9a4f36acdbf50580a312;hp=28bda156b0cf894959495324c0bdfea5c503cf01;hpb=a19cac2195024dc9992fa582eeb4701602695003;p=vlc diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java index 28bda156b0..032008e455 100644 --- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java @@ -36,6 +36,8 @@ public class MediaListPlayer private final JVLC jvlc; + private volatile boolean released; + public MediaListPlayer(JVLC jvlc) { libvlc_exception_t exception = new libvlc_exception_t(); @@ -55,10 +57,25 @@ public class MediaListPlayer return jvlc.getLibvlc().libvlc_media_list_player_is_playing(instance, exception) == 1; } + + /** + * + */ public void play() { libvlc_exception_t exception = new libvlc_exception_t(); jvlc.getLibvlc().libvlc_media_list_player_play(instance, exception); + try + { + while (jvlc.getLibvlc().libvlc_media_list_player_is_playing(instance, exception) == 0) + { + Thread.sleep(25); + } + } + catch(InterruptedException e) + { + // + } } public void stop() @@ -72,24 +89,83 @@ public class MediaListPlayer libvlc_exception_t exception = new libvlc_exception_t(); jvlc.getLibvlc().libvlc_media_list_player_pause(instance, exception); } - + public void next() + { + libvlc_exception_t exception = new libvlc_exception_t(); + jvlc.getLibvlc().libvlc_media_list_player_next(instance, exception); + } + + /** + * Plays the given descriptor and returns only when the player has started to play. + * @param descriptor The media descriptor to play + */ public void playItem(MediaDescriptor descriptor) + { + playItem(descriptor, true); + } + + /** + * @param descriptor The media descriptor to play + * @param synchronous If true it does not return until the player is not playing. + */ + public void playItem(MediaDescriptor descriptor, boolean synchronous) { libvlc_exception_t exception = new libvlc_exception_t(); jvlc.getLibvlc().libvlc_media_list_player_play_item(instance, descriptor.getInstance(), exception); + if (!synchronous) + { + return; + } + + try + { + while (jvlc.getLibvlc().libvlc_media_list_player_is_playing(instance, exception) == 0) + { + Thread.sleep(25); + } + } + catch(InterruptedException e) + { + // + } + } + /** + * Plays the item at the given index and returns only when the player has started to play. + * @param index The item index to play. + */ public void playItem(int index) + { + playItem(index, true); + } + + /** + * @param index The item index to play. + * @param synchronous If true it does not return until the player is not playing. + */ + public void playItem(int index, boolean synchronous) { libvlc_exception_t exception = new libvlc_exception_t(); jvlc.getLibvlc().libvlc_media_list_player_play_item_at_index(instance, index, exception); + try + { + while (jvlc.getLibvlc().libvlc_media_list_player_is_playing(instance, exception) == 0) + { + Thread.sleep(25); + } + } + catch(InterruptedException e) + { + // + } } - public void setMediaInstance(MediaInstance mediaInstance) + public void setMediaInstance(MediaPlayer mediaInstance) { libvlc_exception_t exception = new libvlc_exception_t(); - jvlc.getLibvlc().libvlc_media_list_player_set_media_instance(instance, mediaInstance.getInstance(), exception); + jvlc.getLibvlc().libvlc_media_list_player_set_media_player(instance, mediaInstance.getInstance(), exception); } /** @@ -98,8 +174,22 @@ public class MediaListPlayer @Override protected void finalize() throws Throwable { - jvlc.getLibvlc().libvlc_media_list_player_release(instance); + release(); super.finalize(); } + /** + * + */ + public void release() + { + if (released) + { + return; + } + released = true; + jvlc.getLibvlc().libvlc_media_list_player_release(instance); + + } + }