我想使用 vlcj 在 JPanel 中播放视频。此 JPanel 是 JFrame 中的六个 JPanel 之一。我使用下面的代码来显示视频,但未能成功。JPanel 不显示视频。如果有人能给我一些建议,我将不胜感激。
JPanel 中的代码如下:
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);
}
}