Failed to play video by vlcj in java

只愿长相守 提交于 2019-12-11 06:33:48

问题


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);
}
}

回答1:


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


来源:https://stackoverflow.com/questions/16023836/failed-to-play-video-by-vlcj-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!