Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play a video using JavaFX on Raspberry Pi

I need to run a JavaFX project on Raspberry Pi (RASPBIAN JESSIE). The project includes usage of WebView and MediaView/MediaPlayer. Since Oracle does not support JavaFX on ARM platforms, I tried JavaFX port by Gluon (JavaFX Embedded SDK 8.60.8). WebView works almost perfectly. However, when I want to play a video using MediaPlayer/MediaView, I get the exception:

Error in GstPipelineFactory: can't find element for factory named qtdemux
Exception in Application start 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$156(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
    at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
    at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:511)
    at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:414)
    at zirro.App.start(App.java:21)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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
Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
    at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:224)
    at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:104)
    at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467)
    ... 10 more

Any ideas how to successfully run a JavaFX application with WebView and MediaView/MediaPlayer on Raspberry Pi?

like image 861
FeroG Avatar asked Feb 06 '17 20:02

FeroG


People also ask

Can JavaFX be used with swing?

JavaFX SDK provides the JFXPanel class, which is located in the javafx. embed. swing package and enables you to embed JavaFX content into Swing applications.

Can JavaFX run in a browser?

The recommended way to embed a JavaFX application into a web page or launch it from inside a web browser is to use the Deployment Toolkit library. The Deployment Toolkit provides a JavaScript API to simplify web deployment of JavaFX applications and improve the end user experience with getting the application to start.

Is JavaFX deprecated?

Starting with JDK 11, Oracle will remove JavaFX from the JDK, though will continue to provide commercial support for it in Oracle JDK 8 at least until 2022, according to Oracle's blog.

Can JavaFX be used for games?

JavaFX provides rich GUI for gaming applications. JavaFX also provides beautiful graphics, this graphics are providing in JavaFX by using Canvas. Most of the JavaFX games has time based games so we can add time related operations with AnimationTimer class.


1 Answers

WebView and Media were never part of the JavaFX ARM distribution, but Gluon recently added it to the embedded SDK that can be downloaded from here and installed with a recent JDK for ARM, available here.

Media requires a few extra steps as it depends in the native drivers that usually are not fully installed on a regular Jessie distribution.

First install these drivers:

sudo apt-get install gstreamer0.10-plugins-good
sudo apt-get install gstreamer0.10-plugins-bad 

Now edit /etc/apt/sources.list and add at the end:

deb http://ftp.uk.debian.org/debian/ wheezy main
deb-src http://ftp.uk.debian.org/debian/ wheezy main

Save the file (Ctrl+O, Ctrl+X).

Finally update and install the drivers:

sudo apt-get update
sudo apt-get install gstreamer0.10-ffmpeg
sudo apt-get install gstreamer0.10-alsa

Now you can try to run again your JavaFX application.

If you find again the same exception (MediaException: UNKNOWN), check if it shows this message: Error in GstPipelineFactory, notice the driver that is missing, and try to install it.

like image 121
José Pereda Avatar answered Sep 26 '22 02:09

José Pereda