reading wav files located in in a jar file

Hi all,

is there any way to load a .wav from a jar file or input stream using ALut ?
I am asking because the method alutUnloadWAV only accepts a string.
Or is there a trick to convert the resource url to a string, that can be used?
I tried the following, but it didn’t work. :frowning:

java.net.URL url = ClassLoader.getSystemResource(“MySound.wav”);

// works well
java.io.InputStream in = url.openStream();
in.read();

in.close();

// but I can’t use the file location as an argument to an FileInpuStream -
the exception:thrown, is listed below
ALut.alutLoadWAVFile( url.getFile(), …);

java.io.FileNotFoundException: file:/home/gestalt/code/projects/beergarden/dist/beergarden.jar!/FancyPants.wav (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at com.sun.media.sound.WaveFileReader.getAudioInputStream(WaveFileReader.java:205)
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1162)
at net.java.games.joal.util.WAVLoader.loadFromFile(WAVLoader.java:76)
at net.java.games.joal.util.ALut.alutLoadWAVFile(ALut.java:101)
at net.monoid.beergarden.RendererAL.loadALData(RendererAL.java:138)
at net.monoid.beergarden.RendererAL.(RendererAL.java:77)
at net.monoid.beergarden.Main.main(Main.java:34)

After I have looked at the source code, I noticed that the problem easily could be solved, because:

The method ALut.alutLoadWAVFile(String filename, …) forwards the ‘filename’ variable to theWAVLoader.loadFromFile(String filename, …) and this creates a File object, which is passed to AudioSystem.getAudioInputStream(…). Since this method is overloaded for an InputStream and a URL, the ALut and WAVLoader classes could be updates easily.

Please do so, because otherwise I can’t use these utilities with java webstart.

Best regards
-Michael

I second that!, I actually had the exact same problem and came to the same solution :smiley:

// Gregof

couldn’t you just write your own loader and pass the bytes off to JOAL in some fashion?

If you check out the gluegen-branch-1-0 sources of the JOAL tree this has already been implemented:


cvs co -r gluegen-branch-1-0 joal

However you’ll still need to build this source tree yourself which is a little involved since it requires a built JOGL workspace alongside it. Next week we’ll promote this work to the main trunk and set up nightly builds for JOAL to save you this trouble.

I still need to make such a branch for the joal-demos workspace. I’ll try to do that today.

OK, the gluegen-branch-1-0 branch is there for the joal-demos workspace so you can just add “joal-demos” to the end of the cvs co line above to see examples of the new APIs. If you want I could put up builds for a couple of platforms to hold you over until the nightly builds are up; let me know which platforms.