Pregunta

I wants to use vlcj to play video in a JPanel. This JPanel is one of six JPanels in a JFrame. I used the code below to display the video, but failed to make it. The JPanel does not display the video.I would be really appreciated if anyone could give me some suggestions.

The code in JPanel is listed below:

public class VideoPanel extends JPanel {

private EmbeddedMediaPlayerComponent mymediaPlayer;
private String vlcPath = "d:/Program Files/VideoLAN/VLC";
private String mediaPath = "d:/testvideo/test2.mov";
private EmbeddedMediaPlayer mediaPlayer;

private Canvas canvas;

public VideoPanel() {
    setLayout(new BorderLayout(0, 0));

    Canvas canvas_1 = new Canvas();
    add(canvas_1, BorderLayout.CENTER);

        NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcPath);
    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
    CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas_1);
    mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
    mediaPlayer.setVideoSurface(videoSurface);

    mediaPlayer.playMedia(mediaPath);  
    this.setVisible(true);
}
}
¿Fue útil?

Solución

The problem has been solved. It was caused by I tried to play the video before the frame set the whole panel visible and also the URL of the video file should be set correctly in vlcj 2.1.0.

I change the URL to the correct format and move the playMedia to frame class and call it after the initialization of the Frame.

I found these two discussions very helpful: 1. Trying to embed vlcj media player in a WindowsCanvas inside a JPanel

  1. https://github.com/caprica/vlcj/issues/29
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top