Commit daa85a7f authored by Filippo Carone's avatar Filippo Carone

java bindings huge update

parent 4713a367
...@@ -102,6 +102,7 @@ S: France ...@@ -102,6 +102,7 @@ S: France
N: Filippo Carone N: Filippo Carone
E: filippo[dontspam]@carone.org E: filippo[dontspam]@carone.org
C: littlejohn
D: Java bindings D: Java bindings
S: Italy S: Italy
......
SUBDIRS = python java SUBDIRS = python
#######################################################################
# VLC Java Bindings
#######################################################################
SUBDIRS= . src
EXTRA_DIST= \
FAQ \
TODO \
README \
THANKS \
javadoc.xml \
VlcClient.java \
VLCExample.java
EXTRA_DIST+= \
org/videolan/jvlc/AudioIntf.java \
org/videolan/jvlc/Audio.java \
org/videolan/jvlc/GenericVideoWidget.java \
org/videolan/jvlc/InputIntf.java \
org/videolan/jvlc/Input.java \
org/videolan/jvlc/JLibVLC.java \
org/videolan/jvlc/JVLCCanvas.java \
org/videolan/jvlc/JVLC.java \
org/videolan/jvlc/JVLCPanel.java \
org/videolan/jvlc/PlaylistIntf.java \
org/videolan/jvlc/Playlist.java \
org/videolan/jvlc/VideoIntf.java \
org/videolan/jvlc/Video.java \
org/videolan/jvlc/VLCException.java \
org/videolan/jvlc/VLMIntf.java \
org/videolan/jvlc/VLM.java \
org/videolan/jvlc/listener/VolumeListener.java
if BUILD_JAVA
OBJECTS = org/videolan/jvlc/VLM.class org/videolan/jvlc/VLCException.class org/videolan/jvlc/Playlist.class org/videolan/jvlc/AudioIntf.class org/videolan/jvlc/Audio.class org/videolan/jvlc/InputIntf.class org/videolan/jvlc/Input.class org/videolan/jvlc/PlaylistIntf.class org/videolan/jvlc/VideoIntf.class org/videolan/jvlc/JVLCCanvas.class org/videolan/jvlc/Video.class org/videolan/jvlc/JLibVLC.class org/videolan/jvlc/JVLC.class org/videolan/jvlc/JVLCPanel.class org/videolan/jvlc/VLMIntf.class org/videolan/jvlc/GenericVideoWidget.class org/videolan/jvlc/listener/VolumeListener.class
PROCESSOR_FAMILY = `uname -m | sed -e 's/^i.86/i386/' | sed -e 's/^x86_64/amd64/'`
if HAVE_WIN32
JINCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/win32
LIBJINCLUDES = -L${JAVA_HOME}/lib -ljawt
else
JINCLUDES = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
LIBJINCLUDES = -L$(JAVA_HOME)/jre/lib/$(PROCESSOR_FAMILY) -ljawt
endif
export JINCLUDES
export LIBJINCLUDES
# Build targets
%.class: %.java
$(JAVAC) $?
VlcClient: $(OBJECTS)
$(JAVAC) VlcClient.java
VLCExample: $(OBJECTS)
$(JAVAC) VLCExample.java
all-am: VlcClient VLCExample
clean-local:
rm -f *.class *~ org/videolan/jvlc/*.class src/*.o *.so *.o *.dll
endif
...@@ -2,33 +2,40 @@ ...@@ -2,33 +2,40 @@
First of all, this is a *developers* only version First of all, this is a *developers* only version
Usage Compiling JVLC
----- --------------
In order to use these bindings you have to compile vlc from source. I In order to use these bindings you have to compile vlc from source, be sure
recommend you to take the latest version from videolan svn repository to use the latest git version (see http://wiki.videolan.org/Git for instructions
(or use at least revison 18443) by doing: on how to get the latest vlc version).
svn co svn://svn.videolan.org/vlc/trunk vlc-trunk JVLC depends on JNA, you can download JNA from http://jna.dev.java.net .
bootstrap, clean, set environment variables, configure and build: JVLC is developed using the Sun JDK version 6, but version 5 should be fine too.
./bootstrap Until the build.xml will be ready, you may compile jvlc issueing from the bindings
java folder:
export JAVA_HOME=/path/to/jvm mkdir output
(for example i have JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun) javac -d output -cp <path-to>/jna.jar -g org/videolan/jvlc/internal/*.java org/videolan/jvlc/event/*.java org/videolan/jvlc/*.java VLCExample.java VlcClient.java
./configure --enable-java-bindings && make && make install where <path-to> is the folder where the file jna.jar is contained
and in the output folder you'll find the compiled classes.
You may also import jvlc in eclipse running the createEclipseProject.sh script.
Running JVLC Example
--------------------
To run a Java VLC example issue (be sure you have an a.avi and a.mp3 files To run a Java VLC example issue (be sure you have an a.avi and a.mp3 files
in your user.dir folder): in your user.dir folder):
java -Djava.library.path=/usr/local/lib VLCExample java -cp .:<path-to>jna.jar -Djna.library.path=/usr/local/lib VLCExample
(if you have specified a prefix in configure, change /usr/local/lib to (if you have specified a prefix in configure, change /usr/local/lib to
PREFIX/lib) PREFIX/lib)
Be sure your ldconfig can find libjawt.so and libmawt.so or you will
get linking errors when you run the program.
Happy playing. Happy playing.
import org.videolan.jvlc.AudioIntf;
import org.videolan.jvlc.JVLC; import org.videolan.jvlc.JVLC;
import org.videolan.jvlc.MediaDescriptor;
import org.videolan.jvlc.MediaInstance;
import org.videolan.jvlc.Playlist;
import org.videolan.jvlc.VLCException; import org.videolan.jvlc.VLCException;
import org.videolan.jvlc.listener.VolumeListener; import org.videolan.jvlc.Video;
import org.videolan.jvlc.event.MediaInstanceListener;
public class VLCExample public class VLCExample
...@@ -24,131 +27,147 @@ public class VLCExample ...@@ -24,131 +27,147 @@ public class VLCExample
} }
} }
JVLC jvlc = new JVLC(args); JVLC jvlc = new JVLC(args);
Playlist playlist = new Playlist(jvlc);
System.out.println("... done."); System.out.println("... done.");
try
{
// jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.avi", "a.avi");
jvlc.playlist.add("file:///home/little/a.avi", "a.avi");
// jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.mp3", "a.mp3");
jvlc.playlist.play(-1, null);
}
catch (VLCException e)
{
e.printStackTrace();
}
while (! jvlc.isInputPlaying())
{
Thread.sleep(100);
}
while (! jvlc.hasVout() )
{
Thread.sleep(100);
}
// testing vout functionalities
Thread.sleep(2500);
if (jvlc.hasVout())
{
videoInput = true;
}
if (videoInput) MediaDescriptor mediaDescriptor = new MediaDescriptor(jvlc, "/home/carone/a.avi");
MediaInstance mediaInstance = mediaDescriptor.getMediaInstance();
mediaInstance.addListener(new MediaInstanceListener()
{ {
try @Override
public void endReached(MediaInstance mediaInstance)
{ {
System.out.print(jvlc.video.getWidth()); System.out.println("Media instance end reached. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
System.out.print("x");
System.out.println(jvlc.video.getHeight());
} }
catch (VLCException e)
@Override
public void paused(MediaInstance mediaInstance)
{ {
e.printStackTrace(); System.out.println("Media instance paused. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
} }
}
try
{
if (videoInput)
{
System.out.print("Fullscreen... ");
jvlc.video.setFullscreen(true);
Thread.sleep(3000);
System.out.println("real size.");
jvlc.video.setFullscreen(false);
System.out.print("Taking snapshot... ");
jvlc.video.getSnapshot(System.getProperty("user.dir") + "/snap.png",0,0);
System.out.println("taken. (see " + System.getProperty("user.dir") + "/snap.png )");
Thread.sleep(2000);
System.out.println("Resizing to 300x300");
jvlc.video.setSize(300, 300);
} @Override
jvlc.audio.addVolumeListener(new VolumeListener() public void played(MediaInstance mediaInstance)
{ {
public void volumeChanged() { System.out.println("Media instance played. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
System.out.println("====> From the listener: volume changed."); }
}
});
System.out.print("Muting...");
jvlc.audio.setMute(true);
Thread.sleep(3000);
System.out.println("unmuting.");
jvlc.audio.setMute(false);
Thread.sleep(3000);
System.out.println("Volume is: " + jvlc.audio.getVolume());
System.out.print("Setting volume to 150... ");
jvlc.audio.setVolume(150);
System.out.println("done");
System.out.println("== AUDIO INFO ==");
int currentChannel = jvlc.audio.getChannel();
System.out.println("Audio track number: " + jvlc.audio.getTrack());
System.out.println("Audio channel info: " + jvlc.audio.getChannel());
System.out.print("Setting left channel... ");
jvlc.audio.setChannel(AudioIntf.LEFT_CHANNEL);
System.out.println("done.");
Thread.sleep(3000);
System.out.print("Setting right channel... ");
jvlc.audio.setChannel(AudioIntf.RIGHT_CHANNEL);
System.out.println("done.");
Thread.sleep(3000);
System.out.print("Reverting to original channel");
jvlc.audio.setChannel(currentChannel);
System.out.println("done.");
Thread.sleep(3000);
System.out.println("INPUT INFORMATION");
System.out.println("-----------------");
System.out.println("Total length (ms) :\t" + jvlc.input.getLength());
System.out.println("Input time (ms) :\t" + jvlc.input.getTime());
System.out.println("Input position [0-1]:\t" + jvlc.input.getPosition());
if (videoInput)
System.out.println("Input FPS :\t" + jvlc.input.getFPS());
} @Override
public void positionChanged(MediaInstance mediaInstance)
{
// TODO Auto-generated method stub
}
catch (Exception e) @Override
{ public void timeChanged(MediaInstance mediaInstance, long newTime)
System.out.println("Something was wrong. I die :(."); {
jvlc.destroy(); System.out.println("new time: " + newTime);
e.printStackTrace(); }
System.exit(0); });
} mediaInstance.play();
// MediaInstance mediaInstance = playlist.getMediaInstance();
//
// while (! mediaInstance. playlist.isPlaying())
// {
// Thread.sleep(100);
// }
// while (! jvlc.hasVout() )
// {
// Thread.sleep(100);
// }
System.out.println("Everything fine ;)"); // testing vout functionalities
System.out.println("Playing next item"); // Thread.sleep(2500);
// if (jvlc.hasVout())
// {
// videoInput = true;
// }
//
// if (videoInput)
// {
try try
{ {
jvlc.playlist.next(); Video video = new Video(jvlc);
System.out.print(video.getWidth(mediaInstance));
System.out.print("x");
System.out.println(video.getHeight(mediaInstance));
System.out.print("Fullscreen... ");
video.setFullscreen(mediaInstance, true);
Thread.sleep(3000);
System.out.println("real size.");
video.setFullscreen(mediaInstance, false);
System.out.print("Taking snapshot... ");
video.getSnapshot(mediaInstance, System.getProperty("user.dir") + "/snap.png", 0, 0);
System.out.println("taken. (see " + System.getProperty("user.dir") + "/snap.png )");
Thread.sleep(2000);
System.out.println("Resizing to 300x300");
video.setSize(300, 300);
} }
catch (VLCException e) catch (VLCException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
Thread.sleep(3000); // System.out.print("Muting...");
// jvlc.audio.setMute(true);
// Thread.sleep(3000);
// System.out.println("unmuting.");
// jvlc.audio.setMute(false);
// Thread.sleep(3000);
// System.out.println("Volume is: " + jvlc.audio.getVolume());
// System.out.print("Setting volume to 150... ");
// jvlc.audio.setVolume(150);
// System.out.println("done");
// System.out.println("== AUDIO INFO ==");
// int currentChannel = jvlc.audio.getChannel();
// System.out.println("Audio track number: " + jvlc.audio.getTrack());
// System.out.println("Audio channel info: " + jvlc.audio.getChannel());
// System.out.print("Setting left channel... ");
// jvlc.audio.setChannel(AudioIntf.LEFT_CHANNEL);
// System.out.println("done.");
// Thread.sleep(3000);
// System.out.print("Setting right channel... ");
// jvlc.audio.setChannel(AudioIntf.RIGHT_CHANNEL);
// System.out.println("done.");
// Thread.sleep(3000);
// System.out.print("Reverting to original channel");
// jvlc.audio.setChannel(currentChannel);
// System.out.println("done.");
// Thread.sleep(3000);
// System.out.println("INPUT INFORMATION");
// System.out.println("-----------------");
// System.out.println("Total length (ms) :\t" + jvlc.input.getLength());
// System.out.println("Input time (ms) :\t" + jvlc.input.getTime());
// System.out.println("Input position [0-1]:\t" + jvlc.input.getPosition());
// if (videoInput)
// System.out.println("Input FPS :\t" + jvlc.input.getFPS());
//
// }
//
// catch (Exception e)
// {
// System.out.println("Something was wrong. I die :(.");
// jvlc.destroy();
// e.printStackTrace();
// System.exit(0);
// }
System.out.println("Everything fine ;)");
System.out.println("Playing next item");
// try
// {
// jvlc.playlist.next();
// }
// catch (VLCException e)
// {
// e.printStackTrace();
// }
//
// Thread.sleep(3000);
jvlc.destroy(); // jvlc.destroy();
return; return;
} }
} }
...@@ -23,31 +23,49 @@ ...@@ -23,31 +23,49 @@
* *
*/ */
import java.awt.Canvas;
import java.awt.Frame; import java.awt.Frame;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import org.videolan.jvlc.JVLCPanel; import javax.swing.JPanel;
import org.videolan.jvlc.JVLC; import org.videolan.jvlc.JVLC;
import org.videolan.jvlc.Playlist;
import org.videolan.jvlc.VLCException; import org.videolan.jvlc.VLCException;
class VLCPlayerFrame extends Frame {
public VLCPlayerFrame() { class VLCPlayerFrame extends Frame
{
private Playlist playlist;
public Canvas jvcanvas;
public VLCPlayerFrame()
{
initComponents(); initComponents();
} }
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints; private void initComponents()
{
fullScreenButton = new javax.swing.JButton(); java.awt.GridBagConstraints gridBagConstraints;
jTextField1 = new javax.swing.JTextField();
setButton = new javax.swing.JButton();
pauseButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
jvcc = new JVLCPanel(); fullScreenButton = new javax.swing.JButton();
jvlc = jvcc.getJVLCObject(); jTextField1 = new javax.swing.JTextField();
setButton = new javax.swing.JButton();
pauseButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
jvcc = new JPanel();
jvcanvas = new java.awt.Canvas();
jvcanvas.setSize(200, 200);
jvcc.add(jvcanvas);
jvlc = new JVLC();
playlist = new Playlist(jvlc);
setLayout(new java.awt.GridBagLayout()); setLayout(new java.awt.GridBagLayout());
...@@ -55,11 +73,14 @@ class VLCPlayerFrame extends Frame { ...@@ -55,11 +73,14 @@ class VLCPlayerFrame extends Frame {
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
gridBagConstraints.gridx = 0; gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0; gridBagConstraints.gridy = 0;
add( jvcc , gridBagConstraints); add(jvcc, gridBagConstraints);
fullScreenButton.setText("FullScreen"); fullScreenButton.setText("FullScreen");
fullScreenButton.addActionListener(new java.awt.event.ActionListener() { fullScreenButton.addActionListener(new java.awt.event.ActionListener()
public void actionPerformed(java.awt.event.ActionEvent evt) { {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
fullScreenButtonActionPerformed(evt); fullScreenButtonActionPerformed(evt);
} }
}); });
...@@ -68,8 +89,7 @@ class VLCPlayerFrame extends Frame { ...@@ -68,8 +89,7 @@ class VLCPlayerFrame extends Frame {
gridBagConstraints.gridx = 0; gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2; gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add( fullScreenButton, gridBagConstraints); add(fullScreenButton, gridBagConstraints);
jTextField1.setText("file://a.avi"); jTextField1.setText("file://a.avi");
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints = new java.awt.GridBagConstraints();
...@@ -79,10 +99,12 @@ class VLCPlayerFrame extends Frame { ...@@ -79,10 +99,12 @@ class VLCPlayerFrame extends Frame {
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
add(jTextField1, gridBagConstraints); add(jTextField1, gridBagConstraints);
setButton.setText("Set item"); setButton.setText("Set item");
setButton.addActionListener(new java.awt.event.ActionListener() { setButton.addActionListener(new java.awt.event.ActionListener()
public void actionPerformed(java.awt.event.ActionEvent evt) { {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
setButtonActionPerformed(evt); setButtonActionPerformed(evt);
} }
}); });
...@@ -92,10 +114,12 @@ class VLCPlayerFrame extends Frame { ...@@ -92,10 +114,12 @@ class VLCPlayerFrame extends Frame {
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(setButton, gridBagConstraints); add(setButton, gridBagConstraints);
pauseButton.setText("Play/Pause"); pauseButton.setText("Play/Pause");
pauseButton.addActionListener(new java.awt.event.ActionListener() { pauseButton.addActionListener(new java.awt.event.ActionListener()
public void actionPerformed(java.awt.event.ActionEvent evt) { {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
pauseButtonActionPerformed(evt); pauseButtonActionPerformed(evt);
} }
}); });
...@@ -106,8 +130,11 @@ class VLCPlayerFrame extends Frame { ...@@ -106,8 +130,11 @@ class VLCPlayerFrame extends Frame {
add(pauseButton, gridBagConstraints); add(pauseButton, gridBagConstraints);
stopButton.setText("Stop"); stopButton.setText("Stop");
stopButton.addActionListener(new java.awt.event.ActionListener() { stopButton.addActionListener(new java.awt.event.ActionListener()
public void actionPerformed(java.awt.event.ActionEvent evt) { {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
stopButtonActionPerformed(evt); stopButtonActionPerformed(evt);
} }
}); });
...@@ -116,67 +143,89 @@ class VLCPlayerFrame extends Frame { ...@@ -116,67 +143,89 @@ class VLCPlayerFrame extends Frame {
gridBagConstraints.gridy = 2; gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(stopButton, gridBagConstraints); add(stopButton, gridBagConstraints);
pack(); pack();
} }
private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) { private void stopButtonActionPerformed(java.awt.event.ActionEvent evt)
try { {
//mci.stop(new Position(10000, PositionOrigin.ABSOLUTE, PositionKey.MEDIATIME)); try
jvlc.playlist.stop(); {
} catch (Exception e) { playlist.stop();
}
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) { private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt)
try { {
//System.out.println(mci.getMediaPosition(PositionOrigin.ABSOLUTE, PositionKey.BYTECOUNT)); try
jvlc.playlist.togglePause(); {
} catch (Exception e) { playlist.togglePause();
}
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
private void setButtonActionPerformed(java.awt.event.ActionEvent evt) { private void setButtonActionPerformed(java.awt.event.ActionEvent evt)
try { {
jvlc.playlist.add("file://a.avi", "a.avi"); try
jvlc.playlist.play(-1, null); {
} catch (VLCException e) { jvlc.setVideoOutput(jvcanvas);
// TODO Auto-generated catch block playlist.add(jTextField1.getText(), "a.avi");
e.printStackTrace(); playlist.play();
} }
catch (VLCException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
private void fullScreenButtonActionPerformed(java.awt.event.ActionEvent evt) { private void fullScreenButtonActionPerformed(java.awt.event.ActionEvent evt)
//jvlc.fullScreen(); {
// jvlc.fullScreen();
} }
private javax.swing.JButton setButton; private javax.swing.JButton setButton;
private javax.swing.JButton pauseButton; private javax.swing.JButton pauseButton;
private javax.swing.JButton stopButton; private javax.swing.JButton stopButton;
private javax.swing.JButton fullScreenButton; private javax.swing.JButton fullScreenButton;
private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField1;
private JVLCPanel jvcc;
private JPanel jvcc;
public JVLC jvlc; public JVLC jvlc;
//MediaControlInstance mci; // MediaControlInstance mci;
} }
public class VlcClient { public class VlcClient
{
public static void main(String[] args)
{
Frame f = new VLCPlayerFrame();