Closing InputStream after sound file plays?
Hi everybody,
I've been looking on the web and over the forums and I can't seem to find an answer to this (I think I'm missing something silly). I have code in an application that allows a sound to play, but after the sound plays, I'd like to close the InputStream so it isn't left hanging and I can play a different song if I want. The code I have so far is:
import java.io.FileInputStream;
import java.io.InputStream;
import javax.swing.JOptionPane;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
publicclass Player{
private AudioStream audioStream;
public Player( String song ){
play( song );
}
publicvoid play( String song ){
try{
InputStream in =new FileInputStream("D:\\Musica\\" + song + ".wav");
audioStream =new AudioStream(in);
AudioPlayer.player.start(audioStream);
}catch( Exception e ){
JOptionPane.showMessageDialog( null,"The music file could not be played.","Error", JOptionPane.PLAIN_MESSAGE );
}
}
}
Can anyone tell me what I have to add? Putting in player.stop() just stops the file right away.
Thanks!
Jezzica85
Message was edited by:
jezzica85

