I am using the ogg decoder from Tor-Einar Jarnbjo and have no problem when setting things up to read from a file. When I try and load the file into memory as a byte array and then use the decoder, I get an exception.
// Reading from a file
physOggStream = new FileStream(new RandomAccessFile(fileName, "r"));
// Reading file into memory
FileInputStream fileInputStream = new FileInputStream(sourceFile);
audioSamples = new byte[(int)sourceFile.length()];
fileInputStream.read(audioSamples);
fileInputStream.close();
ByteArrayInputStream baInputStream = new ByteArrayInputStream(audioSamples);
physOggStream = new BasicStream(baInputStream);
// get the first logical Ogg stream
los = (LogicalOggStream) physOggStream.getLogicalStreams().iterator().next();
vs = new VorbisStream(los);
You can see by the comments which version is which. The one line file reading works fine with the last two lines of code. If I use the byte array, the new VorbisStream() throws an index out of bounds exception. I get an error about the header being wrong before that.
Can someone point me to what I’m doing wrong?
Regards,
Dr. A.