public void playClick(String file)
{
try {
Clip clip = AudioSystem.getClip ();
AudioInputStream ais = AudioSystem.getAudioInputStream (new File(file));
clip.open (ais);
clip.start ();
}
catch (Exception e)
{
System.out.println(e);
}
}
I've seen a question which is kind of like this one but I guess I'll be a bit more specific.
So the code above is a method I put in a separate class to be invoked when the user clicks on a button. It seems to work fine without the .close() but I'm still pretty sure there's got to be some pretty good reason why I should use close() even though the file I'm playing is very small?
The sound played is only a .wav file which is a very short beep sound, of very small size. Also if there are some flaws in the code above that you could point out, please do so.
If this happens to be a completely duplicated question, I'll apologize then and I'm hoping you can provide the link to it.