Im trying to make sound effects for my game but i couldn't achieve to play it yet. I have looked up everywhere but everytime that i try to do what i see i always have this error:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at pong.Pong.loadResources(Pong.java:114)
at pong.Pong.<init>(Pong.java:69)
at pong.Pong.main(Pong.java:34)
This the code that i try to run:
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("score.wav"));
AudioFormat format = audioInputStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
clip = (Clip) AudioSystem.getLine(info);
clip.open(audioInputStream);
clip.start();
} catch (UnsupportedAudioFileException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Just to be sure, i placed the same named same wav file under directly the project folder, src folder, res folder too. I would like to have it opened from res folder by the way but first thing i have to do is just fixing the code to play the sound. Then i can work with the path declaration. Any help would be appreciated!