try {
OutputBuffer outputBuffer = null;
int sampleRate = -1, channels = -1;
while (true) {
Header header = bitstream.readFrame();
if (header == null) break;
if (outputBuffer == null) {
channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2;
outputBuffer = new OutputBuffer(channels, false);
decoder.setOutputBuffer(outputBuffer);
sampleRate = header.getSampleRate();
}
try {
decoder.decodeFrame(header, bitstream);
} catch (Exception ignored) {
// JLayer's decoder throws ArrayIndexOutOfBoundsException sometimes!?