I'm trying to create simple audio player for mp3 files which i'm going to use on my Raspberry Pi 4. Because of default OpenJDK which installed on Raspberry Pi not included JavaFX framework, i've installed Java 13 from Bellsoft/Liberica (it can be important for another raspberry users) which have JavaFx on board.
But code below is not working and throwing errors:
media = new Media("path/to/mp3-file");
MediaPlayer mp = new MediaPlayer(media);
Exception in Application init method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application init method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:895)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
at javafx.media/javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
at javafx.media/javafx.scene.media.MediaPlayer.init(MediaPlayer.java:518)
at javafx.media/javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:421)
at sample.FX_Player.init(FX_Player.java:86)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:824)
... 2 more
Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:295)
at javafx.media/com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118)
at javafx.media/javafx.scene.media.MediaPlayer.init(MediaPlayer.java:474)
... 5 more
Exception running application sample.FX_Player
I have read that trouble could be because of bad file path but i've tried different ways and no one is not working
file:///home/pi/test.mp3
file:/home/pi/test.mp3
/home/pi/test.mp3
i faced similar questions:
JavaFX and "MediaException: UNKNOWN ... Could not create player!"
JavaFX Media Player not working
but different paths i tried and i use java version higher than 9
Can someone explain how to solve this trouble?