java vlcj,无法在Java中播放vlcj的视频

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

}

}

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值