【发布时间】:2013-12-30 09:01:25
【问题描述】:
如何在没有安装vlc 的情况下使用库vlcj 播放视频?
我做了什么:
1:下载vlcj 库,vlcj 2.4.1 (zip) 并将所有内容添加到构建路径:
(docs1)
2: 下载libvlc.dll 和libvlccore.dll 并将它们放在项目文件夹中:
(docs2)
(docs3)
3:从 http:(here video) 下载了一个示例视频并将其放在项目文件夹中: sample_mpeg4.mp43:(docs4)
然后我创建了以下类以在swing 中显示视频:
public class MediaPlayer extends JPanel {
// Declares our media player component
private EmbeddedMediaPlayerComponent mediaplayer;
// This string holds the media URL path
private static String mediapath;
private JPanel panel;
public MediaPlayer() {
String projectPath = System.getProperty("user.dir");
String vlcpath = projectPath;
mediapath = projectPath + "\\sample_mpeg42.mp4";
// Check if the .dll is correct
File f = new File(vlcpath + "/libvlc.dll");
System.out.println("VLC PATH CORRECT: " + f.exists());
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcpath);
mediaplayer = new EmbeddedMediaPlayerComponent();
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(mediaplayer, BorderLayout.CENTER);
setLayout(new BorderLayout());
add(mediaplayer, BorderLayout.CENTER);
}
public void play() {
mediaplayer.getMediaPlayer().playMedia(mediapath);
}
public static void main(String[] args) {
MediaPlayer mediaplayer = new MediaPlayer();
JFrame ourframe = new JFrame();
ourframe.setContentPane(mediaplayer);
ourframe.setSize(720, 560);
ourframe.setVisible(true);
mediaplayer.play();
ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
但得到错误:
线程“主”java.lang.RuntimeException 中的异常:加载失败 本机库。错误是“无法加载库 'vlc':...
除了libvlc.dll 和libvlccore.dll,我还需要其他/更多吗?
【问题讨论】:
-
是的,您当然需要所有实际解码和播放视频和音频的插件......