2010-07-05 47 views
1

大家好。我有一個音頻類,播放一個.wav文件。但我想永遠循環它。循環Java AudioInputStream

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

如何使用Clip類中的循環工具描述here

clip.open(inputStream); 
clip.loop(Clip.LOOP_CONTINUOUSLY); 
+0

謝謝。 Taht工作。 – artouiros 2010-07-11 06:18:39