1

I'm trying to play a small MP3 file or two using JavaFX, trying with MediaPlayer and AudioClip but getting an exception in each case. Some kind of compatibility issue?

Technology stack (1) Windows 10 home (2) Java 8 update 211 (3) Java SE Development kit 13.0.1 (4) JavaFX 11.0.2.

Exception reported :

(1) MediaPlayer (when I create a new Media object)

Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x30696d74) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x30696d74

(2) AudioClip (when I create a new AudioClip object)

Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x403bc23b) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x403bc23b

Code listing :

// play a sound clip using Media
private void playMedia1() {
    fullFileName = "short.mp3";
    if (checkFileExists(fullFileName)) {
        File f = new File(fullFileName);
        System.out.println("File URI : " + f.toURI().toString());
        Media media = new Media(f.toURI().toString());
        MediaPlayer mplayer = new MediaPlayer(media);
        mplayer.setAutoPlay(true);
    } else {
        System.out.printf("File %s not found%n", fullFileName);
    }
}

// play a sound clip using AudioClip
private void playMedia2() {
    fullFileName = "short.mp3";
    if (checkFileExists(fullFileName)) {
        File f = new File(fullFileName);
        System.out.println("File URI : " + f.toURI().toString());
        AudioClip clip1 = new AudioClip(f.toURI().toString());
        clip1.play();
    } else {
        System.out.printf("File %s not found%n", fullFileName);
    }
}

// test we can open the specified file
private boolean checkFileExists(String filename) {
    File f = new File(filename);
    return f.exists();
}
James_D
  • 201,275
  • 16
  • 291
  • 322
Simon G
  • 83
  • 3
  • You're not using Java 8; it would not generate that exception (and JavaFX 11 is not compatible with it). See https://stackoverflow.com/questions/54291958/javafx-11-illegalaccesserror-when-creating-label, and note you also need the `javafx.media` module. Also, please format stack traces as code, and see https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks – James_D Aug 07 '20 at 16:02
  • Does this answer your question? [Module error when running JavaFx media application](https://stackoverflow.com/questions/53237287/module-error-when-running-javafx-media-application) – Slaw Aug 07 '20 at 17:07
  • Apologies for the misinformation about my tech stack, which I got partly from 'Settings'. I've just rechecked, and found that I'm using JavaFX 11.0.2 on Java 13.0.1. – Simon G Aug 08 '20 at 18:21
  • I will check out the suggestion about making sure that javafx.media is resolved as a module from the module-path. Thanks for the information. – Simon G Aug 08 '20 at 18:24

0 Answers0