I have a problem… I would like to play sounds that are in a different JAR or ZIP from an applet. At the moment, I load them using the “jar:[url]!/[sound]” technique. It works fine.
However, I would like to have progress bars that keep track of these sounds. I currently have a working progress bar that uses a URLConnection object and a ZipInputStream so I can compare the incoming bytes to the expected bytes. It can return a file’s contents as a byte[]. However, when I try to construct a sound with this code:
// 'input' is the object that reads a file from a stream
byte[] b = input.getBytes("mysound.wav"); /* returns byte[] of the expected length, so I'm pretty sure that there's no extra or missing data */
play(b);
public void play(byte[] b) {
AudioData ad = new AudioData(b);
AudioDataStream = new AudioDataStream(ad);
AudioPlayer.player.start(ads);
}
the AudioPlayer plays the sound with a slight ‘click’ at the beginning, like it’s playing the sound’s header, and if I use a ContinuousDataStream, it plays before each loop of the sound. If I strip the header from the byte[] before calling play(), I hear a corrupted version of the sound (seems reasonable, since AudioData can’t figure out what the sound’s structure if I strip the header…).
Is there a better way to convert a byte[] into a sound?
It seems (I haven’t tried this yet; I get confused by the documentation) that I could use the AudioInputStream and Line object to do this, but I get lost in all of the options and sound engineering jargon.