不能在 Java 应用程序中包含 vlc 库



我尝试为使用 VLCJ 的客户创建媒体播放器,而无需从 VLC 在他们的 PC 中安装 VLC。

我从VLC的官方网站获取此代码,它工作正常,直到我添加嵌入式媒体播放器组件((它得到错误

当我使用

new NativeDiscovery((.discover((;

它工作正常,因为我在我的 PC 中安装了 VLC

但是当我使用

私有静态最终字符串NATIVE_LIBRARY_SEARCH_PATH = "C:\\Program Files\\VideoLAN\\VLC";

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName((,NATIVE_LIBRARY_SEARCH_PATH(;

Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName((, LibVlc.class(;

这是错误日志

14:49:08.471 [main]                  INFO                                                   uk.co.caprica.vlcj.Info - vlcj: 3.10.1
14:49:08.482 [main]                  INFO                                                   uk.co.caprica.vlcj.Info - java: 1.8.0_131 Oracle Corporation
14:49:08.482 [main]                  INFO                                                   uk.co.caprica.vlcj.Info - java home: C:Program FilesJavajre1.8.0_131
14:49:08.483 [main]                  INFO                                                   uk.co.caprica.vlcj.Info - os: Windows 10 10.0 amd64

V: 2.2.6 Umbrella
14:49:08.831 [AWT-EventQueue-0]      DEBUG                uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent - args=[--video-title=vlcj video output, --no-snapshot-preview, --quiet-synchro, --sub-filter=logo:marq, --intf=dummy]
14:49:08.841 [AWT-EventQueue-0]      DEBUG                             uk.co.caprica.vlcj.player.MediaPlayerFactory - initX=null
14:49:08.853 [AWT-EventQueue-0]      INFO                                  uk.co.caprica.vlcj.binding.LibVlcFactory - vlc: 2.2.6 Umbrella, changeset 2.2.6-0-g1aae789
14:49:08.854 [AWT-EventQueue-0]      INFO                                  uk.co.caprica.vlcj.binding.LibVlcFactory - libvlc: C:Program FilesVideoLANVLClibvlc.dll
14:49:08.854 [AWT-EventQueue-0]      DEBUG                             uk.co.caprica.vlcj.player.MediaPlayerFactory - MediaPlayerFactory(libvlc=Proxy interface to Native Library <C:Program FilesVideoLANVLClibvlc.dll@1723334656>,libvlcArgs=[--video-title=vlcj video output, --no-snapshot-preview, --quiet-synchro, --sub-filter=logo:marq, --intf=dummy])
14:49:08.855 [AWT-EventQueue-0]      DEBUG                             uk.co.caprica.vlcj.player.MediaPlayerFactory - jna.library.path=null
14:49:08.856 [AWT-EventQueue-0]      DEBUG                             uk.co.caprica.vlcj.player.MediaPlayerFactory - VLC_PLUGIN_PATH=null
[00000000007ecfc0] core libvlc error: No plugins found! Check your VLC installation.
14:49:08.887 [AWT-EventQueue-0]      DEBUG                             uk.co.caprica.vlcj.player.MediaPlayerFactory - instance=null
14:49:08.888 [AWT-EventQueue-0]      ERROR                             uk.co.caprica.vlcj.player.MediaPlayerFactory - Failed to initialise libvlc
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Failed to initialise libvlc.
This is most often caused either by an invalid vlc option being passed when creating a MediaPlayerFactory or by libvlc being unable to locate the required plugins.
If libvlc is unable to locate the required plugins the instructions below may help:
In the text below <libvlc-path> represents the name of the directory containing "libvlc.dll" and "libvlccore.dll" and <plugins-path> represents the name of the directory containing the vlc plugins...
For libvlc to function correctly the vlc plugins must be available, there are a number of different ways to achieve this:
1. Make sure the plugins are installed in the "<libvlc-path>/plugins" directory, this should be the case with a normal vlc installation.
2. Set the VLC_PLUGIN_PATH operating system environment variable to point to "<plugins-path>".
More information may be available in the log.
at uk.co.caprica.vlcj.player.MediaPlayerFactory.<init>(MediaPlayerFactory.java:300)
at uk.co.caprica.vlcj.player.MediaPlayerFactory.<init>(MediaPlayerFactory.java:259)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.onGetMediaPlayerFactory(EmbeddedMediaPlayerComponent.java:349)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:217)
at tutorial.Tutorial.<init>(Tutorial.java:68)
at tutorial.Tutorial$1.run(Tutorial.java:49)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

你能帮我把VLC捆绑到我的项目中吗

对我来说,最好的解决方案是编写自己的发现策略并将VLC库与应用程序捆绑在一起。这样,就不需要安装 VLC。一切都与应用程序一起提供。

下面是发现策略的示例:

https://github.com/johndeverall/BehaviourCoder/blob/master/src/main/java/de/bochumuniruhr/psy/bio/behaviourcoder/BundledVLCLibsDiscoveryStrategy.java

您可能可以使用上面的链接类进行未编辑。

下面是一个使用示例:

final boolean found = new NativeDiscovery(new BundledVLCLibsDiscoveryStrategy()).discover();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Main(found);
}
}); 

除此之外,您还需要在类路径中包含相关的 VLC 库,就像它们包含在链接项目的 resources 文件夹中一样。

https://github.com/johndeverall/BehaviourCoder/tree/embedded_video_libraries/src/main/resources/lib

目前我只在 Windows 上运行它,但如果你能让它适用于 mac 和/或 linux,我将不胜感激!

我在VLCJ - 3.10.1,JNA 4.1组合中观察到了这个问题。 我通过在pom.xml文件中添加JNA 4.2来解决它。

<dependency>
<groupId>uk.co.caprica</groupId>
<artifactId>vlcj</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.0</version>
</dependency>

然后使用以下代码添加了 VLC 2.2.6 库。

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), System.getProperty("user.dir")+"/lib");
System.setProperty("VLC_PLUGIN_PATH",  System.getProperty("user.dir")+"/lib/plugins");

您可以在此处找到代码示例

因为我没有评论权限... 您是否可能安装了超过 1 个 VLC 安装? 询问的原因是 64 位 jdk/jre 无法使用 32 位 VLC 安装,反之亦然。只是猜测是否可能是VLCJ找到了不正确的vlc版本,然后抛出错误。不过只是在这里猜测。