无法在Java中播放vlcj的视频 [英] Failed to play video by vlcj in java

查看:195
本文介绍了无法在Java中播放vlcj的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用vlcj在JPanel中播放视频.此JPanel是JFrame中六个JPanel之一.我使用下面的代码来显示视频,但未能成功. JPanel不显示视频.如果有人可以给我一些建议,我将不胜感激.

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.

JPanel中的代码如下:

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

推荐答案

问题已解决.这是由于我尝试在框架设置为整个面板可见之前播放视频,并且视频文件的URL也应在vlcj 2.1.0中正确设置.

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.

我将URL更改为正确的格式,并将playMedia移至框架类,并在初始化框架后调用它.

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

我发现这两个讨论非常有帮助: 1. 尝试嵌入vlcj媒体播放器在JPanel内的WindowsCanvas中

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

这篇关于无法在Java中播放vlcj的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆