Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8293971

Loading new Media from resources can sometimes fail when loading from FXML

XMLWordPrintable

    • b04
    • generic
    • generic

        ADDITIONAL SYSTEM INFORMATION :
        Linux Fedora 36
        5.19.8-200.fc36.x86_64
        openjdk version "18.0.2" 2022-07-19
        OpenJDK Runtime Environment (Red_Hat-18.0.2.0.9-1.rolling.fc36) (build 18.0.2+9)
        OpenJDK 64-Bit Server VM (Red_Hat-18.0.2.0.9-1.rolling.fc36) (build 18.0.2+9, mixed mode, sharing)

        A DESCRIPTION OF THE PROBLEM :
        After this commit:
        https://github.com/openjdk/jfx/commit/d1110f479567c314ecb6848700bcf4552509d7e9

        Creating a new Media object using a MP3 file in the resources of a project, you can get exceptions:

        Exception in thread "JavaFX Application Thread" MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!
        at javafx.media@20-ea/javafx.scene.media.Media.<init>(Media.java:411)

        At first glance, the error is in this Locator file in the JavaFX source code:
        https://github.com/openjdk/jfx/blob/master/modules/javafx.media/src/main/java/com/sun/media/jfxmedia/locator/Locator.java

        REGRESSION : Last worked in version 18.0.2.1

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Create a new Media object and load an MP3 from the resources
        2. Watch the Media object throw a MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!

        I've also a GIT repository in which the exception occurs immediately when running the Gradle task 'application':
        https://github.com/CodeDead/opal/tree/development (please make sure to use the development branch as this branch makes use of the latest JavaFX versions)

        Oddly enough, it does not always happen, and loading the file directly from a file location instead of the resources seems to work, but when loading from the resources, you get the exception that the media file signature is not recognized.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        As it worked in JavaFX 18.0.2, creating a Media object using a URI to a project resources location should work.

        ACTUAL -
        Exception in thread "JavaFX Application Thread" MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!
        at javafx.media@20-ea/javafx.scene.media.Media.<init>(Media.java:411)
        at Opal/com.codedead.opal.domain.SoundPane$1.changed(SoundPane.java:73)
        at Opal/com.codedead.opal.domain.SoundPane$1.changed(SoundPane.java:69)
        at javafx.base@20-ea/com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
        at javafx.base@20-ea/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
        at javafx.base@20-ea/javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:104)
        at javafx.base@20-ea/javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:111)
        at javafx.base@20-ea/javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:145)
        at javafx.base@20-ea/javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:50)
        at javafx.base@20-ea/javafx.beans.property.StringProperty.setValue(StringProperty.java:71)
        at Opal/com.codedead.opal.domain.SoundPane.setMediaPath(SoundPane.java:192)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at javafx.base@20-ea/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
        at javafx.fxml@20-ea/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
        at javafx.fxml@20-ea/com.sun.javafx.fxml.ModuleHelper.invoke(ModuleHelper.java:100)
        at javafx.fxml@20-ea/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:259)
        at javafx.fxml@20-ea/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:523)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:373)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:335)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:245)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:778)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2931)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2646)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2555)
        at javafx.fxml@20-ea/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2523)
        at Opal/com.codedead.opal.OpalApplication.start(OpalApplication.java:92)
        at javafx.graphics@20-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
        at javafx.graphics@20-ea/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
        at javafx.graphics@20-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at javafx.graphics@20-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
        at javafx.graphics@20-ea/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics@20-ea/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at javafx.graphics@20-ea/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:316)
        at java.base/java.lang.Thread.run(Thread.java:833)

        ---------- BEGIN SOURCE ----------
        final MediaPlayer mediaPlayer = new MediaPlayer(new Media(getClass().getResource("/path/to/file.mp3").toExternalForm()));

        I've made a free MP3 file available to try with here (royalty and copyright free):
        https://codedead.com/static.mp3
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Revert back to JavaFX 18.0.2

        FREQUENCY : always


              almatvee Alexander Matveev
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: