Search code examples
javaswingvlcj

Unable to play video in JPanel using vlcj in ubuntu 13.04


I am trying to play video in JPanel using vlcj in ubuntu, there is no error. My project builds successfully but does not play the video. When I run the code JFrame comes for a while. When I use same code in windows it plays video and works successfully but in Ubuntu, doesn't.

following is output window.

Code's output window

Following is my code : (I am using vlcj-3.0.1)

import com.sun.jna.NativeLibrary;
import java.awt.BorderLayout;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JPanel;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;

class PlayerPanel
        extends JPanel {

    private File vlcInstallPath = new File("---------------Path of vlc player (installed) --------------");
    private EmbeddedMediaPlayer player;

    public PlayerPanel() {

        NativeLibrary.addSearchPath("libvlc", vlcInstallPath.getAbsolutePath());
        EmbeddedMediaPlayerComponent videoCanvas = new EmbeddedMediaPlayerComponent();
        this.setLayout(new BorderLayout());
        this.add(videoCanvas, BorderLayout.CENTER);
        this.player = videoCanvas.getMediaPlayer();
    }

    public void play (String media) {
        player.prepareMedia(media);
        player.parseMedia();
        player.play();
    }
}

class VideoPlayer
        extends JFrame {

    public VideoPlayer() {
        PlayerPanel player = new PlayerPanel();
        this.setTitle("Swing Video Player");
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLayout(new BorderLayout());
        this.setSize(640, 480);
        this.setLocationRelativeTo(null);
        this.add(player, BorderLayout.CENTER);
        this.validate();
        this.setVisible(true);

        player.play("---------------Path of video we want to play ----------------------");
    }

    public static void main (String[] args) {
        new VideoPlayer();
    }
}

And please tell me which path to give for vlc player in ubuntu. There are more than 5 folders with name vlc. One is in /usr/share/ and other is in /etc/ and so on.


Solution

  • edit:

    1. You find the path "Path of vlc player (installed)" when you run: java -jar vlcj-3.0.1-tests.jar As symbolic link you could use: "/usr/lib/libvlc.so.5"

    2. As this code is pasted in other forums too. There is a ubuntu problem with 32bit java7 and vlc. The problem is well explaind here: https://github.com/caprica/vlcj/issues/62

    As a workaround rename filename.luac At ubuntu 14.04 you find it here: /usr/lib/vlc/lua/meta/reader/filename.luac