vlcj无法在默认安装文件夹中找到插件库,NativeDiscovery可以正常工作

时间:2018-06-18 18:48:08

标签: java jna vlcj

我正在尝试将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();
}
   }

stacktrace:

[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)

知道可能是什么原因?

1 个答案:

答案 0 :(得分:0)

因此,由于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位于同一目录中,这将起作用。