Play video in swing (VLCJ without VLC)

Viewed 5422

How can I play a video in swing with the library vlcj without having vlc installed?

What I have done:

1: Downloaded the vlcj library, vlcj 2.4.1 (zip) and add all to build path: (docs1)

2: Downloaded the libvlc.dll and libvlccore.dll and put them in project folder: (docs2)

(docs3)

3: Downloaded a sample video from http:(here video) and put it in project folder: sample_mpeg4.mp43: (docs4)

I then created the following class to show the video in swing:

public class MediaPlayer extends JPanel {

// Declares our media player component
private EmbeddedMediaPlayerComponent mediaplayer;
// This string holds the media URL path
private static String mediapath;
private JPanel panel;

public MediaPlayer() {
    String projectPath = System.getProperty("user.dir");
    String vlcpath = projectPath;
    mediapath = projectPath + "\\sample_mpeg42.mp4";

    // Check if the .dll is correct
    File f = new File(vlcpath + "/libvlc.dll");
    System.out.println("VLC PATH CORRECT: " + f.exists());

    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcpath);
    mediaplayer = new EmbeddedMediaPlayerComponent();

    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(mediaplayer, BorderLayout.CENTER);
    setLayout(new BorderLayout());
    add(mediaplayer, BorderLayout.CENTER);
}

public void play() {
    mediaplayer.getMediaPlayer().playMedia(mediapath);
}

public static void main(String[] args) {
    MediaPlayer mediaplayer = new MediaPlayer();
    JFrame ourframe = new JFrame();
    ourframe.setContentPane(mediaplayer);
    ourframe.setSize(720, 560);
    ourframe.setVisible(true);
    mediaplayer.play();
    ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

But getting the error:

Exception in thread "main" java.lang.RuntimeException: Failed to load the native library. The error was "Unable to load library 'vlc':...

Do I need to have something else/more then the libvlc.dll and libvlccore.dll?

2 Answers
Related