Issue
I´d like to get Java 11 and JavaFX 11 running on a Raspberry Pi 3. I followed the instructions given by Gluon here: http://docs.gluonhq.com/embedded/ (only differences: I´m running a full Stretch image, not Lite and meanwhile BellSoft released Liberica JDK version 11.0.1 also for ARM, so I used that.)
My application is super simple: a label and a button, when the button is pressed then an mp3 shall be played:
public class HelloFX extends Application
{
@Override
public void start(Stage stage) {
String version = System.getProperty("java.version");
String fxVersion = System.getProperty("javafx.runtime.version");
Label l = new Label ("Java version: " + version + "\nJavaFX version: " + fxVersion);
Button b = new Button("play");
Scene scene = new Scene(new VBox(l, b), 350, 200);
b.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
PlayMp3();
}
});
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
Media media;
void PlayMp3()
{
String resource = "/resources/sound.mp3";
media = new Media(getClass().getResource(resource).toURI().toURL().toString());
MediaPlayer mp = new MediaPlayer(media);
mp.play();
}
On Windows / Eclipse this runs and plays the mp3. On the Raspberry Pi I can execute the application with this command:
sudo /opt/jdk-11.0.1/bin/java --module-path=/opt/armv6hf-sdk/lib/ --add-modules javafx.graphics,javafx.media -cp /home/pi/Java/HelloFX/ -Dprism.verbose=true -Dembedded=monocle -Dglass.platform=Monocle javafx11.HelloFX
The graphics is visible on the display but when I press the button then I get the following exception:
Exception in thread "JavaFX Application Thread" java.lang.UnsatisfiedLinkError: no jfxmedia in java.library.path: [/usr/java/packages/lib, /lib, /usr/lib]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
at java.base/java.lang.System.loadLibrary(System.java:1867)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:150)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:62)
at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.lambda$new$0(NativeMediaManager.java:136)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.<init>(NativeMediaManager.java:107)
at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager$NativeMediaManagerInitializer.<clinit>(NativeMediaManager.java:78)
at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.getDefaultInstance(NativeMediaManager.java:90)
at javafx.media/com.sun.media.jfxmedia.MediaManager.canPlayProtocol(MediaManager.java:78)
at javafx.media/com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:239)
at javafx.media/javafx.scene.media.Media.<init>(Media.java:393)
at javafx11.HelloFX.PlayMp3(HelloFX.java:62)
I found some posts saying that this error message means that Java is looking for a library called "libjfxmedia.so" but I can´t find that file anywhere.
Did I make any mistake or miss anything?
Do I need to change something in the java command to execute the application? (I´m unsure about the --add-modules parameter, it runs the same without this option...)
Is it possible that JavaFX 11 still does not support Media on the Raspberry Pi (I read that v8 also provided by Gluon didn´t)? Whom to ask if it will be supported in the near future?
Solution
What José Pereda wrote is correct, javafx.media was not included and it also didn´t get included in 11 release. But things changed meanwhile, BellSoft recently released their Liberica package (Java including JavaFX) in version 14.0.1 where playing mp3s now works: https://bell-sw.com/pages/downloads/?version=java-14&release=14.0.1+8&os=Linux&bitness=32-bit&architecture=ARM&package=jdk-full
There are still some minor bugs (e. g. mp3 file names must not contain spaces, the length of any mp3 is always infinite) but the basics are working, it even allows to play videos, just see their blog: https://bell-sw.com/announcements/2019/09/12/JDK-JavaFX-Video-Preview/
Please make sure to really use the 14.0.1 and not the first 14 release because several fixes esp. for the Raspberry Pi have been implemented there.
Thanks to the BellSoft team for their great work here!!
Answered By - ThomasM