Java play background music(.wav) using javax.sound

644 views Asked by At


I am trying to play background music for my game using javax.sound. The problem is that only the first half second of the song is playing before stopping. I want the entire song to play. I would attach the .wav file on this post but StackOverflow won't allow files to be attached.

AudioInputStream audioIn = AudioSystem.getAudioInputStream(new File("path/to/file/sound.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
//I've tried both of the following:
clip.start();
clip.loop(Clip.LOOP_CONTINUOUSLY);

Thanks for the help.

0

There are 0 answers