0

I have an swing app. Where I use wav file to make alarm. I put Alarm.wav in folder where I have *.class is bin folder. And it works. I use this code to get wav file and play it.

    InputStream in;
    try {

        InputStream is = getClass().getResourceAsStream("Alarm.wav");
        AudioInputStream audioInputStream = AudioSystem
                .getAudioInputStream(is);       
        AudioPlayer.player.start(audioInputStream);
    } catch (FileNotFoundException e) {

        e.printStackTrace();
    }

But when I made in Eclipse runnable jar there is no sound in my app.

Aku
  • 200
  • 3
  • 9
  • 17
  • Did check whether the wave file gets exported into the JAR file? – LostBoy Jul 02 '13 at 22:38
  • If it is, check whether prepending the file name with / or the correct path works, if not you can mark the file's containing folder as a source folder – LostBoy Jul 02 '13 at 22:44

1 Answers1

0

I have similiar problem. Try use this code:

InputStream in;
    try {

        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(getClass().getResource("Alarm.wav"));       
        AudioPlayer.player.start(audioInputStream);
    } catch (FileNotFoundException e) {

        e.printStackTrace();
    }
Sk1X1
  • 1,305
  • 5
  • 22
  • 50