]> git.sesse.net Git - vlc/blobdiff - bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java
jvlc: LibVlc class updated and code aligned to current native libvlc
[vlc] / bindings / java / core / src / main / java / org / videolan / jvlc / JVLC.java
index b2d29ff9122c7f7809634bbae21336fd92292104..8f0c846cf8249040aae9b2bdd4a3ff58cba48aa2 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,22 +42,23 @@ public class JVLC
 
     private final LibVlc libvlc = LibVlc.SYNC_INSTANCE;
 
-    private MediaList mediaList;
+    private VLM vlm;
+    
+    private Audio audio;
+    
+    private volatile boolean released;
+
+    private Canvas canvas;
     
     public JVLC()
     {
-        String[] args = new String[1];
-        args[0] = "jvlc";
-        instance = createInstance(args);
-        mediaList = new MediaList(this);
+        this(new String[] {});
     }
 
     public JVLC(String[] args)
     {
-        String[] myargs = new String[args.length + 1];
-        myargs[0] = "jvlc";
-        System.arraycopy(args, 0, myargs, 1, args.length);
-        instance = createInstance(myargs);
+        instance = createInstance(args);
+        audio = new Audio(this);
     }
     
     public JVLC(String args)
@@ -67,32 +66,60 @@ public class JVLC
         this(args.split(" "));
     }
 
-    public MediaInstance play(String media)
+    /*
+     * Core methods
+     */
+    private LibVlcInstance createInstance(String[] args)
+    {
+        libvlc_exception_t exception = new libvlc_exception_t();
+        return libvlc.libvlc_new(args.length, args, exception);
+    }
+
+    public MediaPlayer play(String media)
     {
         MediaDescriptor mediaDescriptor = new MediaDescriptor(this, media);
-        MediaInstance mediaInstance = new MediaInstance(mediaDescriptor);
-        mediaInstance.play();
-        return mediaInstance;
+        MediaPlayer mediaPlayer = new MediaPlayer(mediaDescriptor);
+        if (canvas != null)
+        {
+            mediaPlayer.setParent(canvas);
+        }
+        mediaPlayer.play();
+        mediaDescriptor.release();
+        return mediaPlayer;
     }
 
     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;
     }
 
-    /*
-     * Core methods
-     */
-    private LibVlcInstance createInstance(String[] args)
+    public Logger getLogger()
     {
-        libvlc_exception_t exception = new libvlc_exception_t();
-        libvlc.libvlc_exception_init(exception);
+        return new Logger(this);
+    }
 
-        return libvlc.libvlc_new(args.length, args, exception);
+    public VLM getVLM()
+    {
+        if (vlm != null)
+        {
+            vlm.release();
+        }
+        this.vlm = new VLM(this);
+        return vlm;
+    }
+    
+    public LoggerVerbosityLevel getLogVerbosity()
+    {
+        int level = libvlc.libvlc_get_log_verbosity(instance);
+        return LoggerVerbosityLevel.getSeverity(level);
+    }
+
+    public void setLogVerbosity(LoggerVerbosityLevel level)
+    {
+        libvlc.libvlc_set_log_verbosity(instance, level.ordinal());
     }
 
+    
     /**
      * Returns the _instance.
      * @return the _instance
@@ -110,6 +137,25 @@ public class JVLC
     {
         return libvlc;
     }
+    
+    /**
+     * Releases this instance and the native resources.
+     */
+    public void release()
+    {
+        if (released)
+        {
+            return;
+        }
+        released = true;
+        if (vlm != null)
+        {
+            vlm.release();
+            vlm = null;
+        }
+        
+        libvlc.libvlc_release(instance);
+    }
 
     /*
      * (non-Javadoc)
@@ -118,17 +164,16 @@ public class JVLC
     @Override
     protected void finalize() throws Throwable
     {
-        libvlc.libvlc_release(instance);
+        release();
         super.finalize();
     }
-    
+
     /**
-     * Returns the mediaList.
-     * @return the mediaList
+     * @return
      */
-    public MediaList getMediaList()
+    public Audio getAudio()
     {
-        return mediaList;
+        return audio;
     }
     
 }