如何使用 JVLC(VLC 的 Java 绑定)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/127587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use JVLC (Java bindings for VLC)?
提问by asterite
I'm trying to use JVLCbut I can't seem to get it work. I've downloaded the jar, I installed VLCand passed the -D argument to the JVM telling it where VLC is installed. I also tried:
我正在尝试使用JVLC,但似乎无法正常工作。我已经下载了 jar,我安装了VLC并将 -D 参数传递给 JVM,告诉它 VLC 的安装位置。我也试过:
NativeLibrary.addSearchPath("libvlc", "C:\Program Files\VideoLAN\VLC");
with no luck. I always get:
没有运气。我总是得到:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libvlc': The specified module could not be found.
线程“main”中的异常 java.lang.UnsatisfiedLinkError:无法加载库“libvlc”:找不到指定的模块。
Has anyone made it work?
有没有人让它工作?
回答by Steve g
You can get that exception if the dll you are trying to load requires other dlls that are not available. Sorry I can't be of more specific help, but it is something to check out. You can use dependsto walk the dll dependancies.
如果您尝试加载的 dll 需要其他不可用的 dll,您可能会收到该异常。抱歉,我无法提供更具体的帮助,但需要检查一下。您可以使用depends来遍历dll 依赖项。
回答by basszero
Not sure about that NativeLibrary class. Typically when using native libraries, you need to set the system property, "java.library.path", to the location of your native libraries. As suggested, if your native library (dll, so, etc) depends on additional native libraries then the OS will takeover to resolve these dependencies. The OS will have no clue about java.library.path and beging by searching the OS specific path for native libraries. On windows this includes the current PATH environment variable as well as System32 in the windows directory. On linux this is the LD_LIBRARY_PATH / ld.conf setup.
不确定那个 NativeLibrary 类。通常,在使用本机库时,您需要将系统属性“java.library.path”设置为本机库的位置。正如所建议的,如果您的本机库(dll、so 等)依赖于其他本机库,那么操作系统将接管以解决这些依赖项。操作系统将不知道 java.library.path 并通过搜索本机库的操作系统特定路径而开始。在 Windows 上,这包括当前的 PATH 环境变量以及 windows 目录中的 System32。在 linux 上,这是 LD_LIBRARY_PATH / ld.conf 设置。
Try setting the PATH (LD_LIBRARY_PATH) to point to the same location as java.library.path. The only catch is that you can't set this one your process launches (the JVM), it's already too late. You need to have the environment set BEFORE the JVM launches. You can do this vis batch files, shell scripts, Ant, or directly from your IDE.
尝试将 PATH (LD_LIBRARY_PATH) 设置为指向与 java.library.path 相同的位置。唯一的问题是你不能设置这个你的进程启动(JVM),已经太晚了。您需要在 JVM 启动之前设置环境。您可以通过批处理文件、shell 脚本、Ant 或直接从您的 IDE 执行此操作。
回答by Simo Erkinheimo
I had the same problem too and I noticed that it occured only with 64-bit jdk/jre. Works like charm with 32-bit jdk under Win7 x64.
我也有同样的问题,我注意到它只发生在 64 位 jdk/jre 上。在 Win7 x64 下使用 32 位 jdk 就像魅力一样工作。
Have a nice coding!
有一个很好的编码!
-Sipe
-刀槽
回答by Jocelyn
You should try
你应该试试
System.load("C:\Path\To\libvlc.dll");
at least to verify that your library can be loaded. And if not, it may give you useful error messages (it did for me).
至少可以验证您的库是否可以加载。如果没有,它可能会给你有用的错误信息(它对我有用)。
(And as Sipe mentioned, you may be using a 64 bits JRE/JDK, in which case libvlc will never be found (it's 32 bits only). In this case you must switch to using a 32 bits JRE/JDK.)
(正如 Sipe 所提到的,您可能正在使用 64 位 JRE/JDK,在这种情况下将永远找不到 libvlc(只有 32 位)。在这种情况下,您必须切换到使用 32 位 JRE/JDK。)

