]> git.sesse.net Git - vlc/blobdiff - bindings/java/org/videolan/jvlc/JVLC.java
better args handling
[vlc] / bindings / java / org / videolan / jvlc / JVLC.java
index d1dd52e3d4e7771acd1b69baa38fe0a667a47395..18c848ea34b4d3c0faadac69711c84a55eb35bfd 100644 (file)
-package org.videolan.jvlc;
-
 /*****************************************************************************
- * JVLC.java: global class for vlc Java Bindings
+ * JVLC.java: Main Java Class, represents a libvlc_instance_t object
  *****************************************************************************
- * Copyright (C) 1998-2004 the VideoLAN team
  *
- * Authors: Filippo Carone <filippo@carone.org>
+ * Copyright (C) 1998-2006 the VideoLAN team
+ * 
+ * Author: Filippo Carone <filippo@carone.org>
+ *         Philippe Morin <phmorin@free.fr>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Created on 28-feb-2006
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * $Id$
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/**
- * This is the main Java VLC class which represents a vlc_object_t. Through this
- * class it's possible to control media loading/playing. It's possible to have 
- * more than one JVLC object in the same program.
+ * 
  */
-public class JVLC {
 
+
+package org.videolan.jvlc;
+
+
+public class JVLC implements Runnable {
+    
     static {
-       System.loadLibrary("jvlc");
+        System.loadLibrary("jvlc" );
     }
 
-    private int id;
-
     /**
-     * @param args Arguments for the vlc object. These are the same as the
-     * original C version of VLC.
+     * These are set as final since they live along the jvlc object
      */
-    public JVLC(String[] args) {
-        String[] properArgs = new String[args.length + 1];
-        properArgs[0] = "jvlc";
-        for (int i = 0; i < args.length; i++)
-            properArgs[i+1] = args[i];
-
-        this.id = create();
-           init(properArgs);
-    }
+    private final long         _instance;
+    
+    public  final Playlist     playlist;
+    public     final Video             video;
+    public     final Audio             audio;
+    public     final Input             input;
+    public     final VLM               vlm;
+    
+    private boolean beingDestroyed = false;
 
+    /**
+     * This is the time in millis VLC checks for internal status 
+     */
+    private long resolution = 50;
+    
+       private boolean inputPlaying = false;
+       private boolean inputVout = false;
+    
     public JVLC() {
-        new JVLC(new String[]{""});
+        String[] args = new String[1];
+        args[0] = "jvlc";
+        
+        _instance      = createInstance( args );
+        playlist       = new Playlist  ( _instance );
+        video          = new Video             ( _instance );
+        audio          = new Audio             ( _instance );
+        input          = new Input             ( _instance );
+        vlm                    = new VLM               ( _instance );
+        new Thread(this).start();
     }
     
-    /**
-     * @return Returns the ID of the VLC Object
-     */
-    public int getID() {
-        return this.id;
+    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 );
+        playlist       = new Playlist  ( _instance );
+        video          = new Video             ( _instance );
+        audio          = new Audio             ( _instance );
+        input          = new Input             ( _instance );
+        vlm                    = new VLM               ( _instance );
+        
+        new Thread(this).start();
     }
-
+    
     
     /**
-     * Cleanup the VLC Object. It's the equivalent of
-     * calling VLC_Die() and VLC_CleanUp() 
+     * Destroys the current instance of jvlc, cleaning up objects.
+     * This is unreversible.
      */
-    public void quit() {
-        this.die();
-        this.cleanUp();
+    public void destroy() {
+       beingDestroyed = true;
+       _destroy();
     }
 
-    private native int create();
-
-    private native int init(String[] args);
-
-    /**
-     * 
-     * Creates the interface of the videolan player
-     * 
-     * @param moduleName The interface module to display
-     * @param blocking True if the interface is blocking, otherwise it runs on its own thread
-     * @param startPlay True if the player starts to play as soon as the interface is displayed
-     * @return An int which is &lt; 0 on error
+       /*
+     * Core methods
      */
-    public native int addInterface(String moduleName, boolean blocking, boolean startPlay);
+    private native long createInstance( String[] args );
+    private native void _destroy();   
 
-    /**
-     * 
-     * Creates the interface of the videolan player with the default interface
-     * or the interface set by -I
-     * 
-     * @param blocking True if the interface is blocking, otherwise it runs on its own thread
-     * @param startPlay True if the player starts to play as soon as the interface is displayed
-     * @return An int which is &lt; 0 on error
-     */
-    public int addInterface(boolean blocking, boolean startPlay) {
-        return addInterface(null, blocking, startPlay);
+    public long getInstance() throws VLCException {
+        return _instance;
     }
 
-    /**
-     * @return The version of the VideoLan object
+    /*
+     * Getters and setters
      */
-    public native String getVersion();
-
-    public native String getError(int errorCode);
-
-    private native int die();
-
-    private native int cleanUp();
+       public Playlist getPlaylist() throws VLCException {
+               return playlist;
+       }
     
-    public native int setVariable(JVLCVariable jvlcVariable);
-
-    public native JVLCVariable getVariable(String varName); // XXX in progress
-
-    public native int addTarget(String URI, String[] options, int insertMode, int position);
-
-    /**
-     * Plays the media
-     * 
-     * @return An int which is &lt; 0 on error
-     */
-    public native int play();
-   
-    /**
-     * 
-     * Pauses the media. If the media is already paused, pause() restarts it.
-     * 
-     * @return
-     */
-    public native int pause();
 
-    /**
-     * 
-     * Stops the media
-     * 
-     * @return
-     */
-    public native int stop();
-
-    /**
-     * @return True if the player is actually playing something
-     */
-    public native boolean isPlaying();
-
-    /**
-     * @return The absolute position within the media
-     */
-    public native float getPosition();
 
-    public native float setPosition(float position);
-
-    public native int getTime();
-
-    public native int setTime(int seconds, boolean relative);
-
-    public native int getLength();
-
-    public native float speedFaster();
-
-    public native float speedSlower();
-
-    public native int getPlaylistIndex();
-
-    public native int getPlaylistItems();
-
-    public native int playlistNext();
-
-    public native int playlistPrev();
-
-    public native int playlistClear();
-
-    public native int getVolume();
-
-    public native int setVolume(int volume);
-
-    public native int muteVolume();
-
-    public native int fullScreen();
+       /**
+        * 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) {
+                       try {
+                               while (playlist.isRunning()) {
+                                       if (input.isPlaying()) {
+                                               inputPlaying = true;
+                                       }
+                                       else {
+                                               inputPlaying = false;
+                                   }
+                                           
+                                       if (input.hasVout()) {
+                                               inputVout = true;
+                                   }
+                                       else {
+                                               inputVout = false;
+                                   }
+                                       try {
+                                               Thread.sleep(resolution);
+                                       } catch (InterruptedException e) {
+                                               e.printStackTrace();
+                                       } 
+                               }
+                       } catch (VLCException e1) { } // while playlist running
+                  inputPlaying = false;
+                  inputVout = false;
+                       try {
+                               Thread.sleep(resolution);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                       } // try
+               } // while ! being destroyed
+       } // run
 }
+