1

https://i.stack.imgur.com/r7npI.jpg it will leed to my problems

I just want to play some audio files, when some action in the program happens. The problem is that my team and I have different structures of folders after cloning the repo. For me I need to give it a path with SourceCode and they need it without this term. And I'd rather like to outsource the resource folder outside of src.

For me the code needs to be:

aux.playSound("SourceCode/AnwendungGruppeAfx/src/application/resources/systems-online.wav");

But for them that needs to be like in the example in the main.java. Otherwise it leeds to the error: Caused by: MediaException: MEDIA_UNAVAILABLE : C:\Users\david\git\Repo_Gruppe_A\AnwendungGruppeAfx\src\application\resources\systems-online.wav And for my teammates they have the same error with the message SourceCode/SourceCode then.

AudioPlayer.java:

public class AudioPlayer {

    public void playSound(String file) {
        String musicFile = file;
        AudioClip audio = new AudioClip(new File(musicFile).toURI().toString());
        audio.play();
    }
}

For example in the Main.java at the opening of the program:

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();
    }
CptDayDreamer
  • 1,526
  • 6
  • 25
  • 61
  • @charlesLgn i can you the folder or now package resources again with the files in it. We all working on Windows. And even 3 of us that i mentioned with problems on Eclipse. And one on IntelliJ, but i don't know if he has problems or not. Its in imgur now – CptDayDreamer Nov 28 '18 at 13:48
  • @charlesLgn nobody has problems with the path of images. Just soundfiles. I already tried like all possible combinations. Your idea just gives me the exception: MEDIA_UNAVAILABLE : C:\application\resources\systems-online.wav – CptDayDreamer Nov 28 '18 at 13:55
  • I know it works with aux.playSound("SourceCode/AnwendungGruppeAfx/src/application/resources/systems-online.wav"); but this does not help me. because it wont work for the others. They get the exception then with:MEDIA_UNAVAILABLE : C:\Repo_Gruppe_A\SourceCode\SourceCode\AnwendungGruppeAfx\src\application\resources\systems-online.wav – CptDayDreamer Nov 28 '18 at 14:04
  • @charlesLgn unlucky. Again: MEDIA_UNAVAILABLE : C:\Users\david\git\Repo_Gruppe_A\.\resources\systems-online.wav – CptDayDreamer Nov 28 '18 at 14:12
  • what happen if you write `AudioClip audio = new AudioClip(file);` instead of the other ? – charles Lgn Nov 28 '18 at 14:39
  • @charlesLgn i saw it somewhere already in stackoverflow. leeds to a new exception: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'AnwendungGruppeAfx/src/application/resources/systems-online.wav' – CptDayDreamer Nov 28 '18 at 14:47

0 Answers0