Как воспроизвести * .wav цикл, когда достигнут конец?
Мой код выглядит так:
public class SoundPlayer implements Runnable{
public SoundPlayer(String filename){
is=Main.class.getResourceAsStream("sounds/"+filename);
}
@Override
public void run() {
// TODO Auto-generated method stub
playSound();
}
public void playSound(){
try {
audioStream = AudioSystem.getAudioInputStream(is);
} catch (Exception e){
e.printStackTrace();
System.exit(1);
}
audioFormat = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
try {
sourceLine = (SourceDataLine) AudioSystem.getLine(info);
sourceLine.open(audioFormat);
} catch (LineUnavailableException e) {
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
sourceLine.start();
int nBytesRead = 0;
int bufferSize = audioFormat.getFrameSize() *
Math.round(audioFormat.getSampleRate() / 10);
byte[] abData = new byte[bufferSize];
while (nBytesRead != -1) {
try {
nBytesRead = audioStream.read(abData, 0, abData.length);
} catch (IOException e) {
e.printStackTrace();
}
if (nBytesRead >= 0) {
@SuppressWarnings("unused")
int nBytesWritten = sourceLine.write(abData, 0, nBytesRead);
}
else {
audioStream.reset(); //I add this code but didn't effect
}
}
sourceLine.drain();
sourceLine.close();
}
private final int BUFFER_SIZE = 128000;
private File soundFile;
private AudioInputStream audioStream;
private AudioFormat audioFormat;
private SourceDataLine sourceLine;
private InputStream is;
Помогите мне, пожалуйста.