我有这个代码:
public class MediaPanel {
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
chargerLibrairie();
new MediaPanel(args);
}
});
}
static void chargerLibrairie(){ String ruta="C:/VideoLAN/VLC";
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), ruta);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
LibXUtil.initialise();
}
private MediaPanel(String[] args) {
JFrame frame = new JFrame("Tutoriel vlcj");
frame.setLocation(100, 100);
frame.setSize(1050, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
//Créer une instance de Canvas
Canvas c = new Canvas();
//L'arrière plan de la vidéo est noir par défaut
c.setBackground(Color.black);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
//La vidéo prend toute la surface
p.add(c, BorderLayout.CENTER);
frame.add(p, BorderLayout.CENTER);
//Créer une instance factory
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
//Créer une instance lecteur média
EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(c));
//Plein écran
mediaPlayer.toggleFullScreen();
//Cacher le curseur de la souris à l'intérieur de JFrame
mediaPlayer.setEnableMouseInputHandling(false);
//Désactiver le clavier à l'intérieur de JFrame
mediaPlayer.setEnableKeyInputHandling(true);
//Préparer le fichier
mediaPlayer.prepareMedia("J.mp4");
//lire le fichier
mediaPlayer.play();
}
}
我有这个错误:
run:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Unable to load library 'libvlc': Native library (win32-x86-64/libvlc.dll) not found in resource path ([file:/C:/Users/Jes%c3%bas/Desktop/videoProyecto/jna-4.0.0.jar, file:/C:/Users/Jes%c3%bas/Desktop/videoProyecto/jna-platform-4.0.0.jar, file:/C:/Users/Jes%c3%bas/Desktop/videoProyecto/vlcj-2.4.0.jar, file:/C:/Users/Jes%c3%bas/Documents/NetBeansProjects/edicionVideo/build/classes/])
看起来目录是正确的,但我认为它没有从vlc加载库。我已经确保这些库与我的电脑具有相同的架构,64 位,但我真的不知道问题是什么。
最佳答案
有时问题是由于VLC和JRE的架构不兼容造成的。
您可以使用以下代码检查 JRE 架构:
public class JavaApplication12 {
public static void main(String[] args) {
System.out.println(System.getProperty("sun.arch.data.model"));
}
}
如果VLC是32位,那么JRE也必须是32位,如果VLC是64,那么JRE也必须是64位。
关于java - 无法加载库 libvlc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29408258/