gpt4 book ai didi

java - Basic MediaPlayer 在使用 vlcj 时出现 NoClassDefFoundError,NativeLibrary 问题?

转载 作者:行者123 更新时间:2023-12-02 04:33:02 29 4
gpt4 key购买 nike

我正在尝试使用 vlcj 在 netbeans(java) 中播放视频,但我收到此消息...我假设它与 nativeLibrary 有关,但我不确定该怎么做这项工作,我似乎无法在网上找到答案。

package movieplayer;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.windows.Win32FullScreenStrategy;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

public class MediaPlayer extends JPanel {


public static void main(String[] args) {
JFrame ourframe = new JFrame();
ourframe.setLocationRelativeTo(null);
ourframe.setSize(720, 560);
ourframe.setVisible(true);
ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Canvas c = new Canvas();
c.setBackground(Color.black);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());

p.add(c);
ourframe.add(p);

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:/Program Files (x86)/VLC/");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

MediaPlayerFactory mpf = new MediaPlayerFactory();

EmbeddedMediaPlayer emp = mpf.newEmbeddedMediaPlayer(new Win32FullScreenStrategy(ourframe));
emp.setVideoSurface(mpf.newVideoSurface(c));

emp.toggleFullScreen();

emp.setEnableMouseInputHandling(false);

emp.setEnableKeyInputHandling(false);

String file = "C:/Videos/Intro.wmv";

emp.prepareMedia(file);
emp.play();

}
}

这是输出:

run:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at uk.co.caprica.vlcj.runtime.RuntimeUtil.<clinit>(RuntimeUtil.java:35)
at movieplayer.MediaPlayer.main(MediaPlayer.java:39)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

我关注了这个教程视频: https://www.youtube.com/watch?v=XTQ1b3-TUI4

最佳答案

它说找不到记录器Slf4j,你可以下载它 http://www.slf4j.org/download.html

或者使用 mvn api

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>

实现

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>

或者 gradle(也可以在 http://mvnrepository.com/ 上找到)

(注意:如果你不使用其中任何一个,我推荐(据我所知,哪个并不重要),但我发现它非常方便)

关于java - Basic MediaPlayer 在使用 vlcj 时出现 NoClassDefFoundError,NativeLibrary 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31202438/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com