jvlc: video_set_parent does not exist anymore, use media_player_set_(hwnd|xwindow)
authorFilippo Carone <littlejohn@videolan.org>
Sun, 20 Sep 2009 23:56:32 +0000 (01:56 +0200)
committerFilippo Carone <littlejohn@videolan.org>
Sun, 20 Sep 2009 23:56:32 +0000 (01:56 +0200)
core/src/main/java/org/videolan/jvlc/JVLC.java
core/src/main/java/org/videolan/jvlc/MediaPlayer.java
core/src/main/java/org/videolan/jvlc/internal/LibVlc.java
core/src/main/java/org/videolan/jvlc/internal/LibVlcImpl.java
core/src/test/java/org/videolan/jvlc/JVLCTest.java
samples/client/src/main/java/MultipleVideosSample.java

index bcfd949..77ba933 100644 (file)
@@ -35,8 +35,6 @@ import org.videolan.jvlc.internal.LibVlc;
 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
 
-import com.sun.jna.Native;
-
 public class JVLC
 {
 
@@ -44,34 +42,22 @@ public class JVLC
 
     private final LibVlc libvlc = LibVlc.SYNC_INSTANCE;
 
-    private MediaList mediaList;
-    
     private VLM vlm;
     
     private Audio audio;
     
     private volatile boolean released;
 
-    private MediaListPlayer mediaListPlayer;
+    private Canvas canvas;
     
     public JVLC()
     {
-        String[] args = new String[] {};
-        instance = createInstance(args);
-        init();
+        this(new String[] {});
     }
 
     public JVLC(String[] args)
     {
         instance = createInstance(args);
-        init();
-    }
-    
-    private void init()
-    {
-        mediaList = new MediaList(this);
-        mediaListPlayer = new MediaListPlayer(this);
-        mediaListPlayer.setMediaList(mediaList);
         audio = new Audio(this);
     }
     
@@ -93,6 +79,10 @@ public class JVLC
     {
         MediaDescriptor mediaDescriptor = new MediaDescriptor(this, media);
         MediaPlayer mediaPlayer = new MediaPlayer(mediaDescriptor);
+        if (canvas != null)
+        {
+            mediaPlayer.setParent(canvas);
+        }
         mediaPlayer.play();
         mediaDescriptor.release();
         return mediaPlayer;
@@ -100,24 +90,13 @@ public class JVLC
 
     public void setVideoOutput(Canvas canvas)
     {
-        long drawable = Native.getComponentID(canvas);
-        libvlc_exception_t exception = new libvlc_exception_t();
-        libvlc.libvlc_video_set_parent(instance, drawable, exception );
+        this.canvas = canvas;
     }
 
     public Logger getLogger()
     {
         return new Logger(this);
     }
-    
-    /**
-     * Returns the mediaList.
-     * @return the mediaList
-     */
-    public MediaList getMediaList()
-    {
-        return mediaList;
-    }
 
     public VLM getVLM()
     {
@@ -176,8 +155,6 @@ public class JVLC
             vlm.release();
             vlm = null;
         }
-        mediaList.release();
-        mediaListPlayer.release();
         
         libvlc.libvlc_release(instance);
     }
@@ -193,16 +170,6 @@ public class JVLC
         super.finalize();
     }
 
-    
-    /**
-     * Returns the mediaListPlayer.
-     * @return the mediaListPlayer
-     */
-    public MediaListPlayer getMediaListPlayer()
-    {
-        return mediaListPlayer;
-    }
-
     /**
      * @return
      */
index 8590e46..58fb41e 100644 (file)
@@ -25,6 +25,7 @@
 
 package org.videolan.jvlc;
 
+import java.awt.Canvas;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
@@ -37,6 +38,9 @@ import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaPlayer;
 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
 
+import com.sun.jna.Native;
+import com.sun.jna.Platform;
+
 
 public class MediaPlayer
 {
@@ -152,11 +156,11 @@ public class MediaPlayer
         libvlc_exception_t exception = new libvlc_exception_t();
         return libvlc.libvlc_media_player_get_fps(instance, exception);
     }
-    
+
     public boolean isPlaying()
     {
         libvlc_exception_t exception = new libvlc_exception_t();
-        return libvlc.libvlc_media_player_is_playing(instance, exception) == 1? true : false;
+        return libvlc.libvlc_media_player_is_playing(instance, exception) == 1 ? true : false;
     }
 
     public void addListener(final MediaPlayerListener listener)
@@ -172,6 +176,20 @@ public class MediaPlayer
         callbacks.add(callback);
     }
 
+    public void setParent(Canvas canvas)
+    {
+        long drawable = Native.getComponentID(canvas);
+        libvlc_exception_t exception = new libvlc_exception_t();
+        if (Platform.isWindows())
+        {
+            libvlc.libvlc_media_player_set_hwnd(instance, drawable, exception);
+        }
+        else
+        {
+            libvlc.libvlc_media_player_set_xwindow(instance, drawable, exception);
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -191,7 +209,7 @@ public class MediaPlayer
         released = true;
 
         libvlc_exception_t exception = new libvlc_exception_t();
-        for (MediaPlayerCallback callback : callbacks)  
+        for (MediaPlayerCallback callback : callbacks)
         {
             for (LibVlcEventType event : EnumSet.range(
                 LibVlcEventType.libvlc_MediaPlayerPlaying,
@@ -201,9 +219,9 @@ public class MediaPlayer
             }
         }
         libvlc.libvlc_media_player_release(instance);
-        
+
     }
-    
+
     /**
      * Returns the instance.
      * @return the instance
index 7c3b3ed..b770070 100644 (file)
@@ -338,8 +338,14 @@ public interface LibVlc extends Library
     String libvlc_get_changeset();
 
     // video
-
-    void libvlc_video_set_parent(LibVlcInstance libvlc_instance, long drawable, libvlc_exception_t exception);
+    
+    void libvlc_media_player_set_hwnd(LibVlcMediaPlayer mediaplayer_instance, long drawable, libvlc_exception_t exception);
+    
+    long libvlc_media_player_get_hwnd(LibVlcMediaPlayer mediaplayer_instance);
+    
+    void libvlc_media_player_set_xwindow(LibVlcMediaPlayer mediaplayer_instance, long drawable, libvlc_exception_t exception);
+    
+    long libvlc_media_player_get_xwindow(LibVlcMediaPlayer mediaplayer_instance);
 
     void libvlc_toggle_fullscreen(LibVlcMediaPlayer libvlc_instance);
 
index 6140726..d89ceb9 100644 (file)
@@ -38,6 +38,7 @@ import org.videolan.jvlc.internal.LibVlc.LibVlcMediaPlayer;
 import org.videolan.jvlc.internal.LibVlc.libvlc_event_t;
 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
 
+import com.sun.jna.Platform;
 import com.sun.jna.Pointer;
 
 
@@ -119,7 +120,14 @@ public class LibVlcImpl
         
         int drawable = (int) com.sun.jna.Native.getComponentID(canvas);
 
-        libVlc.libvlc_video_set_parent(libvlc_instance_t, drawable, exception);
+        if (Platform.isWindows())
+        {
+            libVlc.libvlc_media_player_set_hwnd(mediaPlayer, drawable, exception);
+        }
+        else
+        {
+            libVlc.libvlc_media_player_set_xwindow(mediaPlayer, drawable, exception);
+        }
         libVlc.libvlc_media_player_play(mediaPlayer, exception);
     }
 }
index ac6b31e..0d8f1ed 100644 (file)
@@ -39,7 +39,7 @@ public class JVLCTest extends AbstractJVLCTest
     public void jvlcNew()
     {
         JVLC jvlc = new JVLC();
-        Assert.assertNotNull(jvlc.getMediaList());
+        Assert.assertNotNull(jvlc.getAudio());
     }
     
     @Test
index 9601af1..1853da8 100644 (file)
@@ -83,6 +83,7 @@ public class MultipleVideosSample
         for (int i = 0; i < videosNumber; i++)
         {
             jvlcArray[i].play(filename);
+            jvlcArray[i].setVideoOutput(videoCanvasesArray[i]);
             Thread.sleep(500);
         }
     }