Posts

Liberica JDK 13 EA with OpenJFX 13 on the Raspberry Pi 4

Sep 12, 2019
Aleksei Voitylov
4.2

Using Liberica JDK 13 EA to play Media with OpenJFX 13 on the Raspberry Pi 4

Today we published Liberica JDK 13 Early Access builds on all supported platforms. As it currently stands, BellSoft provides the most number of platforms publicly for latest Liberica JDK compared to other OpenJDK distribution vendors.

We encourage users to try the preview of all the new features of OpenJDK 13:

  1. Dynamic CDS Archives
  2. ZGC: Uncommit Unused Memory
  3. Reimplement the Legacy Socket API
  4. Switch Expressions (Preview)
  5. Text Blocks (Preview)

With Liberica JDK 13 we will be celebrating the 6th major release of Liberica JDK, so we want to thank our supporters and users with a special gift:

Liberica JDK 13 EA now supports Raspberry Pi 4, the most popular single board computer among enthusiasts. This version adds much more processing capabilities compared to Raspberry Pi 3, that’s why we decided to extend the Java FX Modules supported on the Raspberry Pi by adding OpenJFX Media support on top of OpenJFX Graphics and Controls. Liberica JDK on the Raspberry Pi also now supports Raspbian Buster OS release.

Since Liberica JDK 13 EA builds for ARM 32 Hard Float now include OpenJFX Media, we encourage users to try it out on the Raspberry Pi 4 using the following steps:

  1. Install Raspbian Buster image on the Raspberry Pi 4.
  2. Disable “dtoverlay=vc4-fkms-v3d” boot setting in /boot/config.txt by commenting the relevant line and reboot the Pi.
  3. Run “sudo apt-get install libavcodec-extra libavformat58 libavcodec58 gstreamer1.0-libav” to install the gstreamer backend and relevant codecs.
  4. Install Liberica JDK 13 EA from here.
  5. Download an H.264 Video sample from here.
  6. Compile the following VideoTest example with javac. Or, better yet, develop your own!
  7. Run the VideoTest example, passing the Video sample as command line parameter:
    java VideoTest  simpsons_movie_trailer.mp4
    
    

VideoTest.java:

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.stage.Stage;

import java.io.File;

import javafx.geometry.Pos;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.StackPane;

import javafx.scene.layout.VBox;

import javafx.scene.media.Media;

import javafx.scene.media.MediaPlayer;

import javafx.scene.media.MediaView;

import javafx.scene.text.Text;

public class VideoTest extends Application {

    static String arg0;

    public static void main(String[] args) {

        arg0 = args[0];

        Application.launch(args);

    }

    @Override

    public void start(Stage primaryStage) {

        StackPane root = new StackPane();

        MediaPlayer player = new MediaPlayer(

    	    new Media(getClass().getResource(arg0).toExternalForm()));

        MediaView mediaView = new MediaView(player);

	root.getChildren().add( mediaView);

        Scene scene = new Scene(root, 1024, 768);

        primaryStage.setScene(scene);

        primaryStage.show();

        player.play();

    }

}

On the Raspberry Pi 4 we noticed OpenJFX could play 720p and 1080p video with the same quality as using native mplayer/gstreamer. Make sure you use a cooler with your Raspberry Pi 4 - unlike the Raspberry Pi 3, that thing gets hot!

In this EA release only the X11 GTK backend and H.264 for video playback are known to work. Adding ES2 and Direct FrameBuffer is in the works, and will be made available as soon as some glitches in the Raspberry Pi 4 video driver are resolved.

Video playback takes some time to set up, but after all it feels like a feature you always expected to have. Your feedback is very welcome!

Subcribe to our newsletter

figure

Read the industry news, receive solutions to your problems, and find the ways to save money.

Further reading