]> git.sesse.net Git - vlc/commitdiff
Java bindings update.
authorFilippo Carone <littlejohn@videolan.org>
Sat, 10 Jun 2006 18:13:46 +0000 (18:13 +0000)
committerFilippo Carone <littlejohn@videolan.org>
Sat, 10 Jun 2006 18:13:46 +0000 (18:13 +0000)
- a new java example shows general jvlc use
- more functions added in InputIntf (getInputFPS now works)
- a little potential problem fixed in Playlist

bindings/java/Makefile.am
bindings/java/VLCExample.java [new file with mode: 0644]
bindings/java/org/videolan/jvlc/InputIntf.java
bindings/java/org/videolan/jvlc/JVLC.java
bindings/java/org/videolan/jvlc/Playlist.java
bindings/java/org/videolan/jvlc/VideoIntf.java
bindings/java/vlc-libvlc-jni.cc

index 318fff3bc5ede33173eeb8decd5f05bda82658ea..bb89f683518a97316c301304467f989fe4497c57 100644 (file)
@@ -24,7 +24,7 @@ JAVACXXFLAGS = `top_builddir=../.. ../../vlc-config --cflags pic` -I../../ -I ..
 JAVALDFLAGS = -L../../src -lvlc `top_builddir=../.. ../../vlc-config --libs builtin vlc pic`
 
 # Build targets
-all: libjvlc.so VlcClient
+all: libjvlc.so VlcClient VLCExample
 
 libjvlc.so: vlc-libvlc-jni.o vlc-graphics-jni.o
        $(CXX) -shared vlc-libvlc-jni.o vlc-graphics-jni.o $(LIBJINCLUDES) $(LDFLAGS) $(JAVALDFLAGS) -o libjvlc.so
@@ -38,6 +38,9 @@ vlc-libvlc-jni.o: VlcClient
 VlcClient: $(OBJECTS)
        $(JCC) -C VlcClient.java
 
+VLCExample: $(OBJECTS)
+       $(JCC) -C VLCExample.java
+
 %.class: %.java
        $(JCC) -C $?
        $(JCH) org/videolan/jvlc/$(*F)
diff --git a/bindings/java/VLCExample.java b/bindings/java/VLCExample.java
new file mode 100644 (file)
index 0000000..8b4a8ba
--- /dev/null
@@ -0,0 +1,85 @@
+import org.videolan.jvlc.JVLC;
+
+
+public class VLCExample 
+{
+
+    public static void main( String[] args )
+    {
+       boolean videoInput = false;
+        JVLC jvlc = new JVLC();
+
+        jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.avi", "a.avi");
+       jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.mp3", "a.mp3");
+        jvlc.playlist.play( -1 , null );
+        
+        while (! jvlc.isInputPlaying()) ;
+        
+        // testing vout functionalities
+
+        try {
+               Thread.sleep(500);
+               if (jvlc.hasVout()) videoInput = true;
+               } catch (InterruptedException e) {
+                               e.printStackTrace();
+               }
+
+        if (videoInput) {
+               System.out.print(jvlc.getVideoWidth());
+               System.out.print("x");
+               System.out.println(jvlc.getVideoHeight());
+        }
+        try 
+        {
+               if (videoInput) {
+                       System.out.print("Fullscreen... ");             
+                       jvlc.setFullscreen(true);
+                       Thread.sleep(3000);
+                       System.out.println("real size.");
+                       jvlc.setFullscreen(false);
+               System.out.print("Taking snapshot... ");
+               jvlc.getSnapshot( System.getProperty( "user.dir" ) + "/snap.png");
+               System.out.println("taken. (see " + System.getProperty( "user.dir" ) + "/snap.png )");
+               }
+            System.out.print("Muting...");
+            jvlc.setMute(true);
+            Thread.sleep(3000);
+            System.out.println("unmuting.");
+            jvlc.setMute(false);
+            Thread.sleep(3000);
+            System.out.println("Volume is: " + jvlc.getVolume());
+            System.out.print("Setting volume to 150... ");
+            jvlc.setVolume(150);
+            System.out.println("done");
+            Thread.sleep(3000);
+            System.out.println("INPUT INFORMATION");
+            System.out.println("-----------------");
+            System.out.println("Total length   (ms) :\t" + jvlc.getInputLength());
+            System.out.println("Input time     (ms) :\t" + jvlc.getInputTime());
+            System.out.println("Input position [0-1]:\t" + jvlc.getInputPosition());
+            if (videoInput)
+               System.out.println("Input FPS          :\t" + jvlc.getInputFPS());
+           
+            
+        }
+        
+        catch (Exception e) 
+        {
+               System.out.println("Something was wrong. I die :(.");
+            jvlc.destroy();
+        }
+        
+       System.out.println("Everything fine ;)");
+       System.out.println("Playing next item");
+       jvlc.playlist.next();
+       
+       try {
+               Thread.sleep(3000);
+       } catch (InterruptedException e) {
+               e.printStackTrace();
+       }
+       jvlc.destroy();
+        return;
+    }
+}
+
index ee8a587845d527f93820ba1dac37f7eb5a773cc8..93cb65ebf7969b81df516a49003af0614a454914 100644 (file)
@@ -42,7 +42,7 @@ public interface InputIntf {
      * currently playing playlist item.
      */
     long getInputTime();
-    long getInputPosition();
+    float getInputPosition();
     void setInputTime();
     double getInputFPS();
     
index a7274df21d0a629ac037804be142128442ab79de..37d125f676108b7d97d46b5410da6382899fe6dd 100644 (file)
@@ -93,8 +93,9 @@ public class JVLC implements JLibVLC, Runnable {
      *  Input native methods
      */
     private native long     _getInputLength();
-    private native long     _getInputPosition();
+    private native float    _getInputPosition();
     private native long     _getInputTime();
+    private native float       _getInputFPS();
 
     
     /*
@@ -105,7 +106,7 @@ public class JVLC implements JLibVLC, Runnable {
     private native boolean  _getFullscreen();
     private native int      _getVideoHeight();
     private native int      _getVideoWidth();
-    private native void _getSnapshot(String filename);
+    private native void                _getSnapshot(String filename);
  
     
     public boolean getMute() {
@@ -162,7 +163,7 @@ public class JVLC implements JLibVLC, Runnable {
         return _getInputTime();
     }
 
-    public long getInputPosition() {
+    public float getInputPosition() {
         return _getInputPosition();
         
     }
@@ -173,8 +174,7 @@ public class JVLC implements JLibVLC, Runnable {
     }
 
     public double getInputFPS() {
-        // TODO Auto-generated method stub
-        return 0;
+        return _getInputFPS();
     }
     
     public long getInstance() {
index 0e620662662d43ea7db68da423f27fedf37beecc..5e63e410a33cbb10249456b4e00e873b296f8029 100644 (file)
@@ -56,7 +56,6 @@ public class Playlist implements PlaylistIntf {
 
     public synchronized void play(int id, String[] options) {
         _play(id, options);
-        while (! _inputIsPlaying()) ;
     }
 
     public synchronized void play() {
index 8b0d333cd89cdb03fec78358fb6e95a38bfe2158..8c65610ec8854f6d04d307c00535fc7eef4b899b 100644 (file)
@@ -59,7 +59,9 @@ public interface VideoIntf {
     
     /**
      * Saves a snapshot of the current video window.
-     * @param filepath The full path (including filename) were to save the snapshot to.
+     * @param filepath The full path (including filename) were to save the snapshot to. 
+     * If you only give a path, not including the filename, the snapshot will be saved in
+     * the specified path using vlc naming conventions. 
      */
     void       getSnapshot(String filepath);
     
index 4615d83bff34073803940bb3bb54b6a7d07cc68e..505f7ef77ebe8613b8acad0d07f4d79a55d9b44a 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * JVLC.java: JNI interface for vlc Java Bindings
+ * vlc-libvlc-jni.cc: JNI interface for vlc Java Bindings
  *****************************************************************************
  * Copyright (C) 1998-2006 the VideoLAN team
  *
@@ -180,34 +180,8 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1toggleMute (JNIEnv *env, jo
 }
 
 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC__1getVolume (JNIEnv *env, jobject _this)
-{
-
-    // res is the final result
-    jboolean res;
-    long instance = 0;
-    
-    libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
-
-    libvlc_exception_init( exception );
-
-    instance = getPlaylistInstance( env, _this );
-
-    
-    res = (jboolean) libvlc_audio_get_mute( ( libvlc_instance_t * ) instance, exception );
-    
-    if ( libvlc_exception_raised( exception )) 
-    {
-        ///\TODO: raise java exception
-        printf("%s\n", libvlc_exception_get_message( exception ));
-    }
-
-    free( exception );
 
-    return res;
     
-}
-
-JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC__1getVolume (JNIEnv *env, jobject _this, jboolean value) 
 {
     jint res = 0;
     long instance = 0;
@@ -231,6 +205,8 @@ JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC__1getVolume (JNIEnv *env, job
     return res;
 }
 
+JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC__1getVolume (JNIEnv *env, jobject);
+
 JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1setVolume (JNIEnv *env, jobject _this, jint volume) 
 {
     long instance = 0;
@@ -679,6 +655,47 @@ JNIEXPORT jlong JNICALL Java_org_videolan_jvlc_JVLC__1getInputTime (JNIEnv *env,
     return res;    
 }
 
+JNIEXPORT jfloat JNICALL Java_org_videolan_jvlc_JVLC__1getInputPosition (JNIEnv *env, jobject _this) 
+{
+    float res;
+    long instance = 0;
+    libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ) );
+    libvlc_input_t *input;
+    
+    libvlc_exception_init( exception );
+    
+    instance = getPlaylistInstance( env, _this );
+    
+    input = libvlc_playlist_get_input( ( libvlc_instance_t* ) instance, exception );
+
+    res = libvlc_input_get_position( input, exception );
+    /// \todo handle exceptions
+    free( exception );
+    
+    return res;
+    
+}
+
+JNIEXPORT jfloat JNICALL Java_org_videolan_jvlc_JVLC__1getInputFPS (JNIEnv *env, jobject _this) 
+{
+    float res;
+    long instance = 0;
+    libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ) );
+    libvlc_input_t *input;
+    
+    libvlc_exception_init( exception );
+    
+    instance = getPlaylistInstance( env, _this );
+    
+    input = libvlc_playlist_get_input( ( libvlc_instance_t* ) instance, exception );
+
+    res = libvlc_input_get_fps( input, exception );
+    /// \todo handle exceptions
+    free( exception );
+    
+    return res;
+}
+
 
 
 /*