Search code examples
javajavax.sound.sampled

Looping Java Audio


I've got my Clip loaded.

I can start the Clip using the method clip.start().

However, once the song ends, the clip stops playing (duh).

How do I make it loop continously until I call clip.stop()?

Clip clip = AudioSystem.getClip();
URL url = this.getDeclaringClass().getResource("file.wav");
AudioInputStream s = AudioSystem.getAudioInputStream(url);
clip.open(s);

Solution

  • Should probably use clip.loop(Clip.LOOP_CONTINUOUSLY); rather than clip.start()