[vlc-devel] commit: give the opportunity to play synchronously (Filippo Carone )

git version control git at videolan.org
Fri Mar 21 15:21:29 CET 2008


vlc | branch: master | Filippo Carone <littlejohn at videolan.org> | Fri Mar 21 15:21:52 2008 +0100| [699dd7887738f8e1373a4cf3d8c03f010c70a29b]

give the opportunity to play synchronously

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=699dd7887738f8e1373a4cf3d8c03f010c70a29b
---

 .../java/org/videolan/jvlc/MediaListPlayer.java    |   66 +++++++++++++++++++-
 1 files changed, 65 insertions(+), 1 deletions(-)

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 28bda15..e9a720e 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
@@ -59,6 +59,17 @@ public class MediaListPlayer
     {
         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()
@@ -73,17 +84,70 @@ public class MediaListPlayer
         jvlc.getLibvlc().libvlc_media_list_player_pause(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)




More information about the vlc-devel mailing list