0

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?

  • 1
    Maybe just upgrade your JavaFX version. [This answer (potential duplicate)](https://stackoverflow.com/a/62249425/1155209) notes that some versions of JavaFX (e.g. 11) did not have media support for the Pi. But the answer also notes that JavaFX 14 from Bellsoft/Liberica does provide support for mp3 playback via JavaFX media. The answer also notes certain bugs even in some of the media playback for mp3s on Pi, e.g. filenames with spaces don't work, so perhaps use the most recent version of JavaFX available for the platform, in case some of those bugs were subsequently fixed. – jewelsea Nov 21 '22 at 23:57
  • 1
    [Related post on BellSoft's site](https://bell-sw.com/announcements/2019/09/12/JDK-JavaFX-Video-Preview/): "Using Liberica JDK 13 EA to play Media with OpenJFX 13 on the Raspberry Pi 4". – jewelsea Nov 22 '22 at 00:01
  • 1
    Liberica currently offer "Liberica Full JRE 19 arm 32 for Linux", from their download page. I'm not sure if that is a version that works on a Pi, as I haven't used a Pi, but it may be if you use the deb package installer for it. – jewelsea Nov 22 '22 at 00:10
  • 1
    Alternately, you may be able to follow the [embedded instructions from gluon](https://docs.gluonhq.com/#platforms_embedded). – jewelsea Nov 22 '22 at 00:31
  • 1
    If using liberica, ARMv7 Hard-Float (32 bit), the [release notes](https://bell-sw.com/pages/supported-configurations/) state: “EGL, SW (direct framebuffer) and GTK pipelines are supported. Media functionality is supported in LibericaFX since 11.0.8 and 14.0.2. libavcodec and libavformat packages (such as available in Raspbian Buster) are required for Media functionality in X11. Media functionality for EGL and SW rendering is not supported. Webkit is not supported.”. LibericaFX is included in “Full JDK” and “Full JRE” releases. – jewelsea Nov 22 '22 at 04:53

0 Answers0