tags:

views:

40

answers:

1

Good day everyone. I have an audio class, that plays a .wav file. But i wanna loop it forever.

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class AudioPlayer {{
    new Thread(new Runnable() {
      public void run() {
        try {

          Clip clip = AudioSystem.getClip();
          AudioInputStream inputStream = AudioSystem.getAudioInputStream(AudioPlayer.class.getResourceAsStream("/file.wav"));         
          clip.open(inputStream);
          clip.start(); 
        } catch (Exception e) {
          System.err.println(e.getMessage());
        }
      }
    }).start();  
  }     
}
+1  A: 

How about using the loop facility in the Clip class described here?

clip.open(inputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
bjg
Thanks. Taht worked.