[英]vlcj cannot locate plugins library in default install folder, NativeDiscovery works
我正在嘗試將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)
知道可能是什么原因嗎?
因此,感謝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位於同一目錄中,則此方法有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.