I want to create a game and it should include music which is playing in the background. The music file is a .wav file in a Source Folder.
How can I play music in an executable jar file with my code in the main method:
public class PlayMusic {
public static void main(String[] args) throws LineUnavailableException, IOException, UnsupportedAudioFileException, InterruptedException {
File file = new File("MusicPlayer/SnakeOST.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
clip.start();
clip.loop(Clip.LOOP_CONTINUOUSLY) ;
}
}
This code does work in Eclipse, but after exporting the code there's music missing in the .jar file.