Commit 76c472ef authored by Filippo Carone's avatar Filippo Carone

Java bindings update.

- a new java example shows general jvlc use
- more functions added in InputIntf (getInputFPS now works)
- a little potential problem fixed in Playlist
parent f25c4299
......@@ -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)
......
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;
}
}
......@@ -42,7 +42,7 @@ public interface InputIntf {
* currently playing playlist item.
*/
long getInputTime();
long getInputPosition();
float getInputPosition();
void setInputTime();
double getInputFPS();
......
......@@ -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();
/*
......@@ -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() {
......
......@@ -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() {
......
......@@ -60,6 +60,8 @@ public interface VideoIntf {
/**
* Saves a snapshot of the current video window.
* @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);
......
/*****************************************************************************
* 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;
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment