I am creating an audio player using the Java Sound API (using J2SDK 1.4.2). WAV files are stored in a database. These WAV files are passed to me in the form of a byte array (headers included). Is there any easy way to extract the audio data without building a parser?
I've been creating an AudioInputStream as follows:
byte wavFileBytes = getByteArrayFromDataBase();
ByteArrayInputStream bais = new ByteArrayInputStream(wavFileBytes);
AudioInputStream ais = AudioSystem.getAudioInputStream(bais);
However, when I read the AudioInputStream ( ais.read(...) ) I get the WAV headers as well. Actually, I get back the original byte array (wavFileBytes). I was expecting the call to AudioSystem.getAudioInputStream() to be smart enough to know that headers were in the original byte array. I can actually play this data, but there is an annoying click at the start due to the headers.
I was reviewing how the Java Sound demo does it, but it reads a WAV file from the file system using:
File file = new File("<filepath>");AudioInputStream ais = AudioSystem.getAudioInputStream(file);
In this case, when the AudioInputStream is read only the audio bytes are received.
Does anyone know a way around this problem? Is there a way to treat the byte array as a file?