https://imgur.com/a/6gNa89z它会导致我的问题
当程序中发生某些操作时,我只想播放一些音频文件。问题是我和我的团队在克隆 repo 后有不同的文件夹结构。对我来说,我需要用 SourceCode 给它一个路径,他们需要它而不需要这个术语。而且我宁愿将资源文件夹外包到 src 之外。
对我来说,代码需要是:
aux.playSound("SourceCode/AnwendungGruppeAfx/src/application/resources/systems-online.wav");
但是对于他们来说,这需要像 main.java 中的示例一样。否则会导致错误: 原因:MediaException:MEDIA_UNAVAILABLE :C:\Users\david\git\Repo_Gruppe_A\AnwendungGruppeAfx\src\application\resources\systems-online.wav
对于我的队友来说,他们对消息 SourceCode/SourceCode 也有同样的错误。
音频播放器.java:
public class AudioPlayer {
public void playSound(String file) {
String musicFile = file;
AudioClip audio = new AudioClip(new File(musicFile).toURI().toString());
audio.play();
}
}
例如在 Main.java 中打开程序:
public class Main extends Application {
AudioPlayer aux = new AudioPlayer();
@Override
public void start(Stage primaryStage) throws Exception {
aux.playSound("AnwendungGruppeAfx/src/application/resources/systems-online.wav");
Parent root = FXMLLoader.load(getClass().getResource("/application/controller/LoginController/Login.fxml"));
Scene scene = new Scene(root);
primaryStage.getIcons().add(new Image("/application/resources/icons8-blockchain-technology-64.png"));
primaryStage.setTitle("SemestervErwaltungsPlan");
primaryStage.setResizable(false);
primaryStage.setScene(scene);
primaryStage.show();
}