尝试使用 Java FX 播放 MP3 文件时缺少 kCFURLVolumeIsAutomountedKey

getting kCFURLVolumeIsAutomountedKey missing when trying to play an MP3 file with Java FX

我正在尝试使用 Java FX 播放 MP3 文件,但我不断收到以下错误:

kCFURLVolumeIsAutomountedKey missing for file://localhost/private/var/setup/: 文件“setup”无法打开,因为没有这样的文件。

我检查了我的电脑并显示了隐藏文件,但找不到 localhost 文件夹。

这是 Java 版本的输出,我是 运行:

java 版本“1.8.0_112” Java(TM) SE 运行环境(build 1.8.0_112-b16) Java HotSpot(TM) 64 位服务器 VM(构建 25.112-b16,混合模式) rover-226-42:MP3Player ajgoddu$

我在 Mac 和 OSX Sierra 上,这是我的代码 运行:

    import java.net.URL;
    import javafx.application.Application;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import javafx.stage.Stage;

    public class MP3 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) {
    Media media = new Media( "file:///Users/ajgoddu/Desktop/Projects/Java/MediaPlayer/MP3Player/test.mp3" );
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.play();

    primaryStage.setTitle("Audio Player 1");
    primaryStage.setWidth(200);
    primaryStage.setHeight(200);
    primaryStage.show();
    }
  }

有人知道这个错误的确切含义以及它为什么会发生吗?

谢谢!

看起来您可能需要根据此 slightly unrelated Github issue 下载 XCode CLI 工具。

来自link的问题:

I'm running macOS Sierra V10.12, just updated today. Getting this error message upon running Gulp task: [12:56:04] gulp-notify: [Error in notifier] Error in plugin 'gulp-notify' Message: 2016-09-21 12:56:04.205 terminal-notifier[11630:142879] kCFURLVolumeIsAutomountedKey missing for file:///private/var/setup/: Error Domain=NSCocoaErrorDomain Code=260 "The file “setup” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/setup/, NSFilePath=/private/var/setup, NSUnderlyingError=0x7ffe4d632930 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

答案:

I was also having this issue, and after installing the Xcode CLI tools via xcode-select --install and restarting my machine I stopped receiving the error. It may have just been the restart that sorted it, as installing the CLI tools alone didn't solve the problem.

不幸的是,我在工作时使用的是 Windows 机器,无法在家中使用我的 Mac 进行尝试。希望这对您有所帮助。