how to use a wav file in eclipse
- by AlphaAndOmega
I've been trying to add audio to a project I've been doing. I found some code on here for html that is also supposed to work with file but it keeps saying
"Exception in thread "main" javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at LoopSound.main(LoopSound.java:15)"
the code
public class LoopSound {
public static void main(String[] args) throws Throwable {
File file = new File("c:\\Users\\rabidbun\\Pictures\\10177-m-001.wav");
Clip clip = AudioSystem.getClip();
// getAudioInputStream() also accepts a File or InputStream
AudioInputStream wav = AudioSystem.getAudioInputStream( file );
clip.open(wav);
// loop continuously
clip.loop(-1000);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// A GUI element to prevent the Clip's daemon Thread
// from terminating at the end of the main()
JOptionPane.showMessageDialog(null, "Close to exit!");
}
});
}
}
What is wrong with the code?