大家好日子。我有一个音频类,播放.wav文件。但我想永远地循环它。
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();
}
}
答案 0 :(得分:1)
如何在Clip类中使用循环工具描述here?
clip.open(inputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);