1

I am trying to play a sound when the button is pressed. I am getting this error:

could not get audio input stream from input file

private void spinButtonActionPerformed(java.awt.event.ActionEvent evt) {
    try {
        String roulettespin = "roulettespin.wav";
        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(roulettespin).getAbsoluteFile());
        Clip clip = AudioSystem.getClip();
        clip.open(audioInputStream);
        clip.start();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}
toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
Traplord
  • 101
  • 6
  • I don't code with audio, and so I can't comment on your error. You are 100% sure that you're looking in the right place for the file, that it is in your user's directory? An a side note, consider running that sound in a background thread so as not to freeze your GUI by blocking Swing's event thread. – Hovercraft Full Of Eels Jun 15 '14 at 21:15
  • It might help you, read [play .wav file from jar as resource using java](http://stackoverflow.com/questions/8425481/play-wav-file-from-jar-as-resource-using-java) – Braj Jun 15 '14 at 21:24
  • Does the audio file exist, if so, where does it reside? – MadProgrammer Jun 15 '14 at 22:05
  • Try to put all the path instead of getAbsoluteFile and see if the error persists. es: `new File("C:/Users/Me/roulettesplin.wav")` – Marcello Davi Jun 15 '14 at 22:11
  • 1
    @HovercraftFullOfEels While I would, personally use a background thread, `clip.start` isn't blocking – MadProgrammer Jun 16 '14 at 00:04

0 Answers0