Help file not working
Posted
by meryl
on Stack Overflow
See other posts from Stack Overflow
or by meryl
Published on 2010-04-24T16:40:50Z
Indexed on
2010/04/24
16:43 UTC
Read the original article
Hit count: 221
Hi, can anyone help me ? I wanto to play an audio file and whenever I press the stop button , the already played part of the file should be saved. Unfortunately , what I get is an audio file (.wav) which actually is unplayable.
Thanks
//****************************
void play_cut() {
try {
// First, we get the format of the input file
final AudioFileFormat.Type fileType = AudioSystem.getAudioFileFormat(inputAudio).getType();
// Then, we get a clip for playing the audio.
c = AudioSystem.getClip();
// We get a stream for playing the input file.
AudioInputStream ais = AudioSystem.getAudioInputStream(inputAudio);
// We use the clip to open (but not start) the input stream
c.open(ais);
// We get the format of the audio codec (not the file format we got above)
final AudioFormat audioFormat = ais.getFormat();
c.start();
AudioInputStream startStream = new AudioInputStream(new FileInputStream(inputAudio), audioFormat, c.getLongFramePosition());
AudioSystem.write(startStream, fileType, outputAudio);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}// end play_cut
//****************************
© Stack Overflow or respective owner