hcrnjak
Posts: 2
Joined: Fri Mar 04, 2016 8:41 pm

JavaFX - unable to play Video

Fri Mar 04, 2016 9:29 pm

Hi everyone,

so I'm trying to implement some simple video player using JavaFX.
The idea is to download .mp4 videos, store them on sd card, and then play on demand.
As you can see, nothing special. :)
And it works flawlessly on my laptop.

But as you can imagine, it doesn't work on Raspberry PI (2 model B).
First time I tried to run my JAR I got an error that main class can't be loaded.
I found out that JavaFX is not part of newer embedded versions of JDK8.

So I in order to overcome this issue I downloaded and set up :
- JDK 8u73 for ARM
- OpenJFX 8u40 for armv6hf
Both of these were the latest versions I could find.

So now I can "start" my application but, when the app tries to use FX Media components (player, view, etc.) in order to play Video, I get the following problem :

Java HotSpot(TM) Client VM warning: You have loaded library /home/pi/java/jdk1.8.0_73/jre/lib/arm/libjfxmedia.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.

Exception in Application start method
Exception in Application stop method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsatisfiedLinkError: /home/pi/java/jdk1.8.0_73/jre/lib/arm/libjfxmedia.so: /home/pi/java/jdk1.8.0_73/jre/lib/arm/libjfxmedia.so: wrong ELF class: ELFCLASS64 (Possible cause: architecture word width mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoader.java:201)
at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:94)
at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:39)
at com.sun.media.jfxmediaimpl.NativeMediaManager.lambda$new$5(NativeMediaManager.java:113)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.media.jfxmediaimpl.NativeMediaManager.<init>(NativeMediaManager.java:104)
at com.sun.media.jfxmediaimpl.NativeMediaManager$NativeMediaManagerInitializer.<clinit>(NativeMediaManager.java:75)
at com.sun.media.jfxmediaimpl.NativeMediaManager.getDefaultInstance(NativeMediaManager.java:87)
at com.sun.media.jfxmedia.MediaManager.canPlayContentType(MediaManager.java:64)
at com.sun.media.jfxmedia.locator.Locator.init(Locator.java:431)
at javafx.scene.media.Media.<init>(Media.java:399)
at domain.model.view.GalleryVideo.<init>(GalleryVideo.java:13)
at domain.GalleryContentProvider.lambda$loadItems$0(GalleryContentProvider.java:78)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at domain.GalleryContentProvider.loadItems(GalleryContentProvider.java:68)
at domain.GalleryContentProvider.initialize(GalleryContentProvider.java:57)
at Main.start(Main.java:75)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
... 1 more
Exception running application Main

Has anyone seen this error?
What can I do to fix it?

Thanks in advance!

Best regards,
Hrvoje

Michi.Doswald
Posts: 1
Joined: Fri Mar 11, 2016 12:01 pm

Re: JavaFX - unable to play Video

Fri Mar 11, 2016 12:13 pm

Hi,

The Media components are not officially supported/provided in the embedded build (see https://wiki.openjdk.java.net/display/OpenJFX/Platforms).
I believe to remember, that building the embedded OpenJFX project copied the arm64 libraries for the media components into the resulting SDK folder. These do of course not work with the arm binaries. To get the Media components for ARM, I think you must build the OpenJFX SDK yourself. I don't know if the Media components can now be compiled out-of-the-box or if you need to manually change the gradle scripts to actually compile the Media components. Last time I tried I also had to change some of the Makefiles for gstreamer-lite or so. But I believe the gstreamer version was updated after my tests so I don't know exactly what is needed to get it to build. And after you built it, I don't know if the libraries will actually work :-(

I may be looking into this soon, as I have a project on the horizon who would also need media support on the Raspi. But if you get it to work, please post your results here for all the people who might need it, thanks.

Regards,
Michael

Return to “Java”