#1033771 libopenjfx-java: javafx.scene.media does not support available libav versions

#1033771#5
Date:
2023-04-01 04:49:18 UTC
From:
To:
Dear Maintainer,

This problem was found trying to play an mp3 using Clojure (the JVM hosted language). Constructing a javafx.scene.media.MediaPlayer failed with an exception:

com.sun.media.jfxmedia.MediaException
   Could not create player!

I have investigated the issue and believe that the problem is due to the version of libavcodec in Debian. At the moment Debian has 2 options:

$ aptitude search "libavcodec[0-9]*$" -F %p
libavcodec58
libavcodec59
libavcodec59:i386

However, OpenJFX only added support for 58 in v13 (https://bugs.openjdk.org/browse/JDK-8215894) and 59 in v20 (https://bugs.openjdk.org/browse/JDK-8294400). Neither option allows mp3 playback.

I changed my project dependencies to use javafx-media version 20 and it worked as expected.

;; deps.edn
org.openjfx/javafx-media {:mvn/version "20"}

;; Code
(import [javafx.scene.media Media MediaPlayer])
(import [javafx.application Platform])

(Platform/startup identity)

(def media (-> "audio/screen-saver.mp3" io/resource .toExternalForm Media.))
(def player (MediaPlayer. media))

(.play player)