Well, technically this is not really OGG related I don’t think. But I’m not sure where else to post this. But I have the craziest thing, I have an AudioInputStream that eventually just blocks on a read and never comes back. The crazy thing is the same class running on a different machine doesn’t block! And I’m using the same version of the JVM. I’m going nuts trying to figure this one out. I used the same OGG file to create the stream, have the same class, same jvm just different machines and on one machine the read blocks and the other the read returns an EOF properly. Please, any help would seriously be appreciated as I’m going crazy on this one. Here’s the class I’m using:
import javax.sound.sampled.*;
import java.io.*;
public class OggTest
{
public static void main(String[] args)
{
try
{
File songFile = new File(args[0]);
AudioInputStream ais = AudioSystem.getAudioInputStream(songFile);
AudioFormat afVorbis = AudioSystem.getAudioFileFormat(songFile).getFormat();
AudioFormat afPCM = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
afVorbis.getSampleRate(), 16, afVorbis.getChannels(),
afVorbis.getChannels() * 2, afVorbis.getSampleRate(), false);
ais = AudioSystem.getAudioInputStream(afPCM, ais);
DataLine.Info dli = new DataLine.Info(SourceDataLine.class, ais.getFormat());
SourceDataLine sdl = (SourceDataLine) AudioSystem.getLine(dli);
sdl.open(ais.getFormat());
sdl.start();
int bytesRead = 0;
byte[] byteBuffer = new byte[128000];
while (bytesRead != -1)
{
// The problem is this read blocks on the very last read and never returns
bytesRead = ais.read(byteBuffer, 0, byteBuffer.length);
if (bytesRead != -1)
{
sdl.write(byteBuffer, 0, bytesRead);
}
}
sdl.drain();
sdl.stop();
sdl.close();
}
catch (Exception e)
{
e.printStackTrace();
}
System.exit(0);
}
}