Audio does not play in Jar but does in eclipse

前端 未结 4 1972
眼角桃花
眼角桃花 2021-01-27 08:36

Sound does not play when I run the JAR, but it does when I run it in eclipse.

Here is where I load the clips:

public void init(){
    System.out.println         


        
4条回答
  •  隐瞒了意图╮
    2021-01-27 09:14

    In order to run your current code, the folder music should be in the same folder the jar file is located in.

    Another solution is to package your music folder inside the jar file and then change your code to:

    InputStream is = getClass().getResourceAsStream("/music/" + name[x]);
    AudioInputStream sound = AudioSystem.getAudioInputStream(is);
    

提交回复
热议问题