MediaPlayer 不播放文件名中的某些字符

MediaPlayer don't play with some characters in the filename

MediaPlayer 适用于大多数文件,除非文件名中有一些字符。

MediaException: MEDIA_UNAVAILABLE : T:\Music\Paradis - Hémisph?re.m4a (The system cannot find the file specified)

    public static void play(File song) {
    // Checks if file exists
    if (!song.exists()) {
        System.out.println("Song doesn't exist! " + song.getAbsolutePath());
        return;
    }

    Media media = new Media(song.toURI().toString());
    player = new MediaPlayer(media);

    player.play();

}

调用函数的代码:

FXMediaPlayer.play(new File("T:\Music\Paradis - Hémisphère.m4a"));

部分字符是:é ê ä

我应该如何正确解析文件名,还是 MediaPlayer 有问题?

已解决!我必须将文件名编码为 UTF-8。

还必须将“+”替换为“%20”,更多信息:

不支持带有 UTF-8 字符的文件名,因为它给了我 URISyntaxException

String filePath = null;
    try {
        //Encoding filename to UTF-8, doesn't support folders with UTF-8 characters
        filePath = song.getParentFile().toURI().toString()
                + URLEncoder.encode(song.getName(), "UTF-8").replace("+", "%20");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
Media media = new Media(filePath);