Hi, everyone .

The following code works perfectly for playing audio files.
I'd like to add another functionality .

While playing , if I press the stop button I want the already played
part of the file to get saved in another file.

Any help , especially in terms of code, will be highly appreciated.

thank you!




.................................................. .........

private void playAudio() {
try{
File soundFile = new File("555.wav");
audioInputStream = AudioSystem.
getAudioInputStream(soundFile);
audioFormat = audioInputStream.getFormat();
System.out.println(audioFormat);

DataLine.Info dataLineInfo =
new DataLine.Info(
SourceDataLine.class,
audioFormat);

sourceDataLine =
(SourceDataLine)AudioSystem.getLine(
dataLineInfo);

new PlayThread().start();

}catch (Exception e) {
e.printStackTrace();
System.exit(0);
}//end catch
}//end playAudio

//Inner class to play back the data from the audio file.

class PlayThread extends Thread{
byte tempBuffer[] = new byte[10000];

public void run(){
try{
sourceDataLine.open(audioFormat);
sourceDataLine.start();

int cnt;

while((cnt = audioInputStream.read(
tempBuffer,0,tempBuffer.length)) != -1){
if(cnt > 0){
sourceDataLine.write(
tempBuffer, 0, cnt);
}//end if
}//end while

sourceDataLine.drain();
sourceDataLine.close();

}

.................................................. .........