英文:
Java.lang.UnsatisfiedLinkError: Can't load library when loading mp3 file
问题
我是 Java 新手,正在尝试使我的 JavaFX 应用程序播放声音。但是,我无法创建一个 javafx.scene.media.Media 对象,因为我一直在收到异常。
java.lang.UnsatisfiedLinkError: 无法加载库:C:\Users\Cliente\.jdks\corretto-1.8.0_252\jre\bin\glib-lite.dll
这里是产生此错误的代码片段。
Media sound = new Media(new File("./data/audio/Bomb.mp3").toURI().toString());
我猜测这是由于我的 URI 格式错误导致的,但我不明白为什么这与我看过的教程不同。我的音频文件位于项目根文件夹内的 /data/audio 目录中。有人能帮帮我吗?
英文:
I'm new to java and I'm trying to make my javafx application play a sound. I'm not being able though to create a javafx.scene.media.Media object as I keep getting the exception.
java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\Cliente\.jdks\corretto-1.8.0_252\jre\bin\glib-lite.dll
Here is the piece of code that is generating this error.
Media sound = new Media(new File("./data/audio/Bomb.mp3").toURI().toString());
I imagine that this is being generated by my uri being wrongly formatted but I can't see why this is different from tutorials I've seen. My audio file finds itself in /data/audio which is inside the root folder of the project. Can anyone help me?
答案1
得分: 4
我认为你的问题与创建 Media
对象无关。
Amazon Corretto 适用于 Java 8,并不支持 JavaFX。请查看以下 Github 问题 和 此评论:
> 你好。在 Corretto 8 中的 OpenJFX 8 版本目前只会得到安全补丁和关键修复。在上游,OpenJFX 8 已被废弃(参见 https://hg.openjdk.java.net/openjfx)。
> 推荐的 JavaFX 使用方式是在 Corretto 11 中,并单独引入 OpenJFX,例如使用 Maven 依赖。最新版本(目前为 14)与 Corretto 11 兼容。
> 关闭此问题。
请遵循建议的方法,或者使用其他不同的 Java 发行版。
另请参见此 1 2 Stack Overflow 问题,希望它们能有所帮助。
英文:
I think your problem has nothing to do with the creation of the Media
object.
Amazon Corretto for Java 8 does not support JavaFX. Please, see the following Github issue and this comment:
> Hi. The build of OpenJFX 8 in Corretto 8 is currently on life support and we only plan to apply security patches and critical fixes. Upstream, OpenJFX 8 is abandoned (see https://hg.openjdk.java.net/openjfx).
> The recommended way of using JavaFX is with Corretto 11 and pulling in OpenJFX separately e.g. with a Maven dependency. The latest version (currently 14) is compatible with Corretto 11.
> Closing this issue.
Please, follow the suggested approach, or use a different Java distribution instead.
Please, see also this 1 2 SO questions, I hope they will be help.
答案2
得分: 2
Media sound = new Media(new File("./data/audio/Bomb.mp3").toURI().getPath());
英文:
Media sound = new Media(new File("./data/audio/Bomb.mp3").toURI().toString());
^ issue.
use
Media sound = new Media(new File("./data/audio/Bomb.mp3").toURI().getPath());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论