Commit 53e8222b authored by Clément Stenac's avatar Clément Stenac

Java bindings by Filippo Carone.

Tweaked to integrate into build system
parent 7f2b618b
......@@ -100,6 +100,11 @@ C: bozo
D: SDL video output
S: France
N: Filippo Carone
E: filippo[dontspam]@carone.org
D: Java bindings
S: Italy
N: Tony Castley
E: tony@castley.net
C: tcastley
......
SUBDIRS = python
SUBDIRS = python java
#######################################################################
# VLC Java Bindings
#######################################################################
if BUILD_JAVA
OBJECTS = org/videolan/jvlc/JVLCNoSuchVariableNameException.class org/videolan/jvlc/JVLCBoolVariable.class org/videolan/jvlc/JVLCIntVariable.class org/videolan/jvlc/JVLCTimeVariable.class org/videolan/jvlc/JVLCVarValue.class org/videolan/jvlc/JVLCVariable.class org/videolan/jvlc/JVLCFloatVariable.class org/videolan/jvlc/JVLCStringVariable.class org/videolan/jvlc/JVLCVarVariable.class org/videolan/jvlc/JVLC.class org/videolan/jvlc/JVLCCanvas.class
JNIHEADERS = org/videolan/jvlc/JVLCNoSuchVariableNameException.h org_videolan_jvlc_JVLCBoolVariable.h org_videolan_jvlc_JVLCFloatVariable.h org_videolan_jvlc_JVLC.h org_videolan_jvlc_JVLCIntVariable.h org_videolan_jvlc_JVLCStringVariable.h org_videolan_jvlc_JVLCTimeVariable.h org_videolan_jvlc_JVLCVariable.h org_videolan_jvlc_JVLCVarValue.h org_videolan_jvlc_JVLCVarVariable.h org_videolan_jvlc_JVLCCanvas.h
# Include some JAVA stuff
JINCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux
LIBJINCLUDES = -L${JAVA_HOME}/jre/lib/i386 -ljawt
# Binaries
JCC = gcj -g
JCH = gcjh -jni
# Compile flags
CXXFLAGS += `top_builddir=../.. ../../vlc-config --cflags` -I../../ -I ../../include ${JINCLUDES}
LDFLAGS += -L../../lib -lvlc_pic -fPIC `top_builddir=../.. ../../vlc-config --libs builtin pic`
# Build targets
all: libjvlc.so VlcClient
# FIXME: -ldbus-1 and -lhal are UGLY
# Problem is vlc-config --libs builtin does not output what is needed to build
# vlc. We need to clean up vlc-config first
libjvlc.so: vlc-glue-jni.o vlc-graphics-jni.o
$(CXX) -ldbus-1 -lhal -shared vlc-glue-jni.o vlc-graphics-jni.o $(LIBJINCLUDES) ${LDFLAGS} -o libjvlc.so
vlc-graphics-jni.o: VlcClient
$(CXX) -c vlc-graphics-jni.cc $(CXXFLAGS)
vlc-glue-jni.o: VlcClient
$(CXX) -c vlc-glue-jni.cc $(CXXFLAGS)
VlcClient: $(OBJECTS)
$(JCC) -C VlcClient.java
%.class: %.java
$(JCC) -C $?
$(JCH) org/videolan/jvlc/$(*F)
clean:
rm -f *.class *~ org/videolan/jvlc/*.class org_videolan*.h *.so *.o
endif
First of all, this is a *developers* only version
Usage
-----
In order to use these bindings you have to compile vlc from source. I
recommend you to take the latest version from videolan svn repository
by doing:
svn co svn://svn.videolan.org/vlc/trunk vlc-trunk
bootstrap and configure. At the configure give the command:
./configure --enable-mozilla && make && make install
to enable compilation of _pic version of libraries. If you give a
prefix be sure to change the PREFIX variable in the Makefile from
/usr/local to your prefix.
Once you've done with vlc you can run make in jvlc directory. Be sure
you have gcj, gcjh and if you want to use the SUN Java compiler,
change the Makefile accordingly. You will probably need to change also
JINCLUDES
LIBJINCLUDES
In the next releases I will automate this process.
To run JVLC issue:
java -Djava.library.path=. VlcClient
Be sure your ldconfig can find libjawt.so and libmawt.so or you will
get linking errors when you run the program.
Happy playing.
\ No newline at end of file
[MediaControl - in progress]
* enums will be final classes with private constructor, for type safety
[JNI]
* mediacontrol
[general]
* JUnit testing
* configure / make install
* find a good way to divide CNI and JNI versions (same Java classes,
different interfaces) maybe: two JVLC.java classes, one with the
System.loadLibray for jni and the other without
[CNI]
* mediacontrol
Items are ordered by priority, the first having the highest priority
import org.videolan.jvlc.*;
import java.awt.*;
import java.awt.event.*;
class VLCPlayerFrame extends Frame {
public VLCPlayerFrame() {
initComponents();
}
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
fullScreenButton = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
setButton = new javax.swing.JButton();
pauseButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
// jPanel = new javax.swing.JPanel();
jvcc = new JVLCCanvas();
jvlc = jvcc.getJVLCObject();
// jPanel.add( jvcc );
add( jvcc );
// FIXME: Does not work with GridBagLayout
setLayout(new java.awt.GridLayout(3,2));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
// add( jPanel , gridBagConstraints);
fullScreenButton.setText("FullScreen");
fullScreenButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fullScreenButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add( fullScreenButton, gridBagConstraints);
jTextField1.setText("URL");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
add(jTextField1, gridBagConstraints);
setButton.setText("Set item");
setButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
setButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(setButton, gridBagConstraints);
pauseButton.setText("Play/Pause");
pauseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pauseButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(pauseButton, gridBagConstraints);
stopButton.setText("Stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(stopButton, gridBagConstraints);
pack();
}
private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {
jvlc.stop();
}
private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {
jvlc.pause();
}
private void setButtonActionPerformed(java.awt.event.ActionEvent evt) {
jvlc.stop();
jvlc.playlistClear();
jvlc.addTarget( jTextField1.getText(), null, 1, -666 );
jvlc.play();
}
private void fullScreenButtonActionPerformed(java.awt.event.ActionEvent evt) {
jvlc.fullScreen();
}
private javax.swing.JButton setButton;
private javax.swing.JButton pauseButton;
private javax.swing.JButton stopButton;
private javax.swing.JButton fullScreenButton;
private javax.swing.JTextField jTextField1;
private javax.swing.JPanel jPanel;
private JVLCCanvas jvcc;
public JVLC jvlc;
}
public class VlcClient {
public static void main(String[] args) {
Frame f = new VLCPlayerFrame();
f.setBounds(0, 0, 500, 500);
f.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
} );
f.setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project default="javadoc">
<target name="javadoc">
<javadoc access="public" author="true" classpath="." destdir="doc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" source="1.4" sourcefiles="org/videolan/jvlc/JVLC.java" sourcepath="." splitindex="true" use="true" version="true"/>
</target>
</project>
package org.videolan.jvlc;
/*****************************************************************************
* JVLC.java: global class for vlc Java Bindings
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
*
* Authors: Filippo Carone <filippo@carone.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, 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 {
static {
System.loadLibrary("jvlc");
}
private int id;
/**
* @param args Arguments for the vlc object. These are the same as the
* original C version of VLC.
*/
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);
}
public JVLC() {
new JVLC(new String[]{""});
}
/**
* @return Returns the ID of the VLC Object
*/
public int getID() {
return this.id;
}
/**
* Cleanup the VLC Object. It's the equivalent of
* calling VLC_Die() and VLC_CleanUp()
*/
public void quit() {
this.die();
this.cleanUp();
}
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
*/
public native int addInterface(String moduleName, boolean blocking, boolean startPlay);
/**
*
* 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);
}
/**
* @return The version of the VideoLan object
*/
public native String getVersion();
public native String getError(int errorCode);
private native int die();
private native int cleanUp();
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();
}
package org.videolan.jvlc;
/*****************************************************************************
* JVLC.java: global class for vlc Java Bindings
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
*
* Authors: Filippo Carone <filippo@carone.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/**
* This class is part of JVLC<Type>Variable pool.
*/
public class JVLCBoolVariable extends JVLCVariable {
public JVLCBoolVariable(String name, int value) throws JVLCNoSuchVariableNameException {
super(name);
this.value = (value != 0)? new Integer(1) : new Integer(0);
}
public int getBoolValue() {
return ((Integer)value).intValue();
}
}
/*
* Created on 25-nov-2005
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
*/
/**
* @author Filippo Carone <filippo@carone.org>
*/
package org.videolan.jvlc;
import java.awt.Canvas;
import java.awt.Graphics;
public class JVLCCanvas extends Canvas {
public native void paint(Graphics g);
private final JVLC jvlcObject = new JVLC();
public JVLCCanvas() {
jvlcObject.addInterface("dummy", false, false);
}
public JVLC getJVLCObject() {
return jvlcObject;
}
}
package org.videolan.jvlc;
/*****************************************************************************
* JVLC.java: global class for vlc Java Bindings
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
*
* Authors: Filippo Carone <filippo@carone.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/**
* This class is part of JVLC<Type>Variable pool.
*/
public class JVLCFloatVariable extends JVLCVariable {
public JVLCFloatVariable(String name, float value) throws JVLCNoSuchVariableNameException {
super(name);
this.value = new Float(value);
}
public float getFloatValue() {
return ((Float)value).floatValue();
}
}
package org.videolan.jvlc;
/*****************************************************************************
* JVLC.java: global class for vlc Java Bindings
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
*
* Authors: Filippo Carone <filippo@carone.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/**
* This class is part of JVLC<Type>Variable pool.
*/
public class JVLCIntVariable extends JVLCVariable {
public JVLCIntVariable(String name, int value) throws JVLCNoSuchVariableNameException {
super(name);
this.value = new Integer(value);
}
public int getIntValue() {
return ((Integer)value).intValue();
}
}
/*
* Created on 22-nov-2005
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
*/
/**
* @author Filippo Carone <filippo@carone.org>
*/
package org.videolan.jvlc;
public class JVLCNoSuchVariableNameException extends Exception {
public JVLCNoSuchVariableNameException() {
super();
// TODO Auto-generated constructor stub
}
public JVLCNoSuchVariableNameException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public JVLCNoSuchVariableNameException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public JVLCNoSuchVariableNameException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}
package org.videolan.jvlc;
/*****************************************************************************
* JVLC.java: global class for vlc Java Bindings
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
*
* Authors: Filippo Carone <filippo@carone.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/**
* This class is part of JVLC<Type>Variable pool.
*/
public class JVLCStringVariable extends JVLCVariable {
public JVLCStringVariable(String name, String value) throws JVLCNoSuchVariableNameException {
super(name);
this.value = value;
}
public String getStringValue() {
return (String)value;
}
}