Playing Video file using VLCJ library in java

In this we are going to see how to play an video file using vlcj library in java, It is very simple and works great.. Thanks to VLC team.

Now Some Requirements

1 . VLC Media player version 2.1.5 minimum.

2. VLCJ 3.0.1 can download from

https://code.google.com/p/vlcj/downloads/list

………………………………………………………………………………….

Now create a class and add VLCJ , platform and jna library from VLCJ distribution pack which can download from above link.

Coding :

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

public class VLCPlayer {

private EmbeddedMediaPlayerComponent mediaPlayerComponent;

//This is the path for libvlc.dll
static String VLCLIBPATH = “C:\\Program Files (x86)\\VideoLAN\\VLC”;
public static void main(String[] args) {
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), VLCLIBPATH);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
VLCPlayer vlcPlayer = new VLCPlayer(“Fedora”);
}
});

}
private VLCPlayer() {

//MAXIMIZE TO SCREEN
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

JFrame frame = new JFrame(“VLC Player”);

mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

frame.setContentPane(mediaPlayerComponent);

frame.setLocation(0, 0);
frame.setSize(screenSize.width, screenSize.height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

mediaPlayerComponent.getMediaPlayer().playMedia(“Movie name”);//Movie name which want to play
}
}

Now compile and run the VLCPlayer.java

you can view the frame opened with playing the video specified

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s