【问题标题】:vlcj cannot locate plugins library in default install folder, NativeDiscovery worksvlcj 无法在默认安装文件夹中找到插件库,NativeDiscovery 有效
【发布时间】:2018-06-18 18:48:07
【问题描述】:

我正在尝试将 vlcj 与我的 java 应用程序捆绑在一起,但是如果没有本机发现,我无法加载 vlcj。 我的 Java 和 VLC 安装都是 64 位的,所以应该没有问题。使用本机发现时,我可以让我的视频正常播放。 我尝试了 JNA 3.5.2、JNA 4.1.0、JNA 4.5.1 并且都产生了相同的结果

我能得到的最简单的例子:

public class Test {

private final JFrame frame;

private final EmbeddedMediaPlayerComponent mediaPlayerComponent;

public static void main(final String[] args) {

    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files\\VideoLAN\\VLC");
    System.setProperty("VLC_PLUGIN_PATH",  "C:\\Program Files\\VideoLAN\\VLC\\plugins");
    System.out.println(LibVlc.INSTANCE.libvlc_get_version());

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            new Test(args);
        }
    });
   }

public Test(String[] args) {
    frame = new JFrame("My First Media Player");
    frame.setBounds(100, 100, 600, 400);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            mediaPlayerComponent.release();
            System.exit(0);
        }
    });
    mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
}
   }

堆栈跟踪:

[main] INFO uk.co.caprica.vlcj.Info - vlcj: 3.10.1
[main] INFO uk.co.caprica.vlcj.Info - java: 10.0.1 Oracle Corporation
[main] INFO uk.co.caprica.vlcj.Info - java home: C:\Program Files\Java\jdk-10.0.1
[main] INFO uk.co.caprica.vlcj.Info - os: Windows 10 10.0 amd64
3.0.3 Vetinari
[AWT-EventQueue-0] INFO uk.co.caprica.vlcj.binding.LibVlcFactory - vlc:      3.0.3 Vetinari, changeset 3.0.3-1-0-gc2bb759264
[AWT-EventQueue-0] INFO uk.co.caprica.vlcj.binding.LibVlcFactory - libvlc: C:\Program Files\VideoLAN\VLC\libvlc.dll
[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 vlctest.Test.<init>(Test.java:46)
at vlctest.Test$1.run(Test.java:30)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue.access$600(EventQueue.java:97)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

知道可能是什么原因吗?

【问题讨论】:

  • 顺便说一下,System.setProperty 属性不是系统环境属性。如果您使用终端启动程序或在 IDE 的运行选项中,则可以通过终端设置环境变量。
  • 感谢cubrr,您确实为我指明了正确的方向。它现在在 eclipse 中运行,并设置了环境变量。我认为 vlcj 一直在不设置环境变量的情况下工作。因此,如果我理解正确,我需要做的就是将 env var 设置为插件路径,我可以通过简单地创建一个批处理文件来设置 env var 然后运行我的 jar 文件,或者更好地编写一个小的基本相同的 C 程序。

标签: java jna vlcj


【解决方案1】:

多亏了 cubrr,我才得以解决这个问题。只需创建一个设置环境变量的批处理文件,然后运行 ​​jar 即可。

set VLC_PLUGIN_PATH=C:\Program Files\VideoLAN\VLC\plugins
start cmd.exe /c start "" javaw -jar test.jar

请注意,使用 javaw 运行 jar 会使控制台窗口关闭,因此它不会停留在应用程序窗口下方,而使用 java 会使控制台停留。

也只是把这个留在这里: ClassLoader 可用于加载 libvlc.dll 和 libvlccore.dll

File jarDir = new File(ClassLoader.getSystemClassLoader().getResource(".").getPath());
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), jarDir.getAbsolutePath());`

如果您的 jar 文件和 dll 在同一目录中,这将起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-17
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多