1

我正在尝试使用 JavaFX 播放一个或两个小的 MP3 文件,尝试使用 MediaPlayer 和 AudioClip,但在每种情况下都会出现异常。某种兼容性问题?

技术栈 (1) Windows 10 home (2) Java 8 update 211 (3) Java SE Development kit 13.0.1 (4) JavaFX 11.0.2。

异常报告:

(1) MediaPlayer(当我创建一个新的 Media 对象时)

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(当我创建一个新的 AudioClip 对象时)

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

代码清单:

// 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();
}
4

0 回答 0