]> git.sesse.net Git - vlc/blobdiff - bindings/java/org/videolan/jvlc/JVLC.java
java bindings huge update
[vlc] / bindings / java / org / videolan / jvlc / JVLC.java
index 37d125f676108b7d97d46b5410da6382899fe6dd..7ffaa18e0eb6be403a23982cd617c5338d5ab5eb 100644 (file)
@@ -2,13 +2,14 @@
  * JVLC.java: Main Java Class, represents a libvlc_instance_t object
  *****************************************************************************
  *
- * Copyright (C) 1998-2006 the VideoLAN team
+ * Copyright (C) 1998-2008 the VideoLAN team
  * 
  * Author: Filippo Carone <filippo@carone.org>
- * 
+ *         Philippe Morin <phmorin@free.fr>
+ *
  * Created on 28-feb-2006
  *
- * $Id$
+ * $Id: JVLC.java 20141 2007-05-16 19:31:35Z littlejohn $
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General Public License
  * 
  */
 
-
 package org.videolan.jvlc;
 
-/**
- * @author little
- *
- */
-public class JVLC implements JLibVLC, Runnable {
-    
-    static {
-        System.load(System.getProperty( "user.dir" ) + "/libjvlc.so" );
-    }
+import org.videolan.jvlc.internal.LibVlc;
+import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
+import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
 
-    /**
-     * These are set as final since they live along the jvlc object
-     */
-    private final long _instance;
-    public  final Playlist playlist;
+import com.sun.jna.Native;
 
-    
-    private boolean beingDestroyed = false;
-    private long resolution = 50;
-       private boolean inputPlaying = false;
-       private boolean inputVout = false;
-    
-    public JVLC() {
-        _instance = createInstance();
-        playlist = new Playlist( _instance );
-        new Thread(this).start();
-    }
-    
-    public JVLC(String[] args) {
-        _instance = createInstance( args );
-        playlist = new Playlist( _instance );
-        new Thread(this).start();
-    }
-    
-    
-    /**
-     * Destroys the current instance of jvlc, cleaning up objects.
-     * This is unreversible.
-     */
-    public void destroy() {
-       beingDestroyed = true;
-       _destroy();
-    }
+import java.awt.Canvas;
 
-       /*
-     * Core methods
-     */
-    private native long createInstance();
-    private native long createInstance( String[] args );
-    private native void _destroy();   
-    /*
-     *         Audio native methods
-     */
-    private native boolean     _getMute();
-    private native void                _setMute( boolean value );
-    private native void                _toggleMute();
-    private native int         _getVolume();
-    private native void                _setVolume( int volume );
+public class JVLC
+{
 
-    /*
-     *  Input native methods
-     */
-    private native long     _getInputLength();
-    private native float    _getInputPosition();
-    private native long     _getInputTime();
-    private native float       _getInputFPS();
+    private final LibVlcInstance instance;
 
+    private final LibVlc libvlc = LibVlc.SYNC_INSTANCE;
     
-    /*
-     * Video native methods
-     */
-    private native void     _toggleFullscreen();
-    private native void     _setFullscreen( boolean value);
-    private native boolean  _getFullscreen();
-    private native int      _getVideoHeight();
-    private native int      _getVideoWidth();
-    private native void                _getSnapshot(String filename);
-    
-    public boolean getMute() {
-        return _getMute();
+    public JVLC()
+    {
+        String[] args = new String[1];
+        args[0] = "jvlc";
+        instance = createInstance(args);
     }
 
-    public void setMute(boolean value) {
-        _setMute( value );
-        
-    }
-    
-    public void toggleMute() {
-       _toggleMute();
+    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);
     }
 
-    public int getVolume() {
-        return _getVolume();        
+    public MediaInstance play(String media)
+    {
+        MediaDescriptor mediaDescriptor = new MediaDescriptor(this, media);
+        MediaInstance mediaInstance = new MediaInstance(mediaDescriptor);
+        mediaInstance.play();
+        return mediaInstance;
     }
 
-    public void setVolume(int volume) {
-        _setVolume( volume );
-        
+    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 );
     }
 
-    public void toggleFullscreen() {
-        _toggleFullscreen();
-        
-    }
-
-    public void setFullscreen( boolean value ) {
-        _setFullscreen( value );
-        
-    }
-
-    public boolean getFullscreen() {
-       return _getFullscreen();        
-    }
-
-    public int getVideoHeight() {
-        return _getVideoHeight();
-    }
-    
-
-    public int getVideoWidth() {
-        return _getVideoWidth();        
-    }
-
-    
-    public long getInputLength() {
-        return _getInputLength();        
-    }
-
-    public long getInputTime() {
-        return _getInputTime();
-    }
+    /*
+     * Core methods
+     */
+    private LibVlcInstance createInstance(String[] args)
+    {
+        libvlc_exception_t exception = new libvlc_exception_t();
+        libvlc.libvlc_exception_init(exception);
 
-    public float getInputPosition() {
-        return _getInputPosition();
-        
+        return libvlc.libvlc_new(args.length, args, exception);
     }
 
-    public void setInputTime() {
-        // TODO Auto-generated method stub
-        
+    /**
+     * Returns the _instance.
+     * @return the _instance
+     */
+    LibVlcInstance getInstance()
+    {
+        return instance;
     }
 
-    public double getInputFPS() {
-        return _getInputFPS();
-    }
-    
-    public long getInstance() {
-        return _instance;
+    /**
+     * Returns the libvlc.
+     * @return the libvlc
+     */
+    LibVlc getLibvlc()
+    {
+        return libvlc;
     }
 
     /*
-     * Getters and setters
+     * (non-Javadoc)
+     * @see java.lang.Object#finalize()
      */
-       public Playlist getPlaylist() {
-               return playlist;
-       }
-    
-
-       public void getSnapshot(String filename) {
-               _getSnapshot(filename);
-       }
-       
-       /**
-        * Checks if the input is playing.
-        * @return True if there is a playing input.
-        */
-       public boolean isInputPlaying() {
-               return inputPlaying;
-       }
-
-       /**
-        * Checks if the input has spawned a video window.
-        * @return True if there is a video window.
-        */
-       public boolean hasVout() {
-               return inputVout;
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see java.lang.Runnable#run()
-        * 
-        * In this thread we check the playlist and input status.
-        */
-       public void run() {
-               while (! beingDestroyed) {
-                       while (playlist.isRunning()) {
-                               if (playlist.inputIsPlaying()) {
-                                       inputPlaying = true;
-                               }
-                               else {
-                                       inputPlaying = false;
-                }
-                           
-                               if (playlist.inputHasVout()) {
-                                       inputVout = true;
-                }
-                               else {
-                                       inputVout = false;
-                }
-                               try {
-                                       Thread.sleep(resolution);
-                               } catch (InterruptedException e) {
-                                       e.printStackTrace();
-                               } 
-                       } // while playlist running
-                  inputPlaying = false;
-                  inputVout = false;
-                       try {
-                               Thread.sleep(resolution);
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                       } // try
-               } // while ! being destroyed
-       } // run
-
+    @Override
+    protected void finalize() throws Throwable
+    {
+        libvlc.libvlc_release(instance);
+        super.finalize();
+    }
 }
-