'Vorbis SPI throws UnsupportedAudioFileException for OGG files
I'm trying to play an OGG Vorbis file from a Java program. PCM files (*.wav) work fine with this code:
public void play(String resFile) throws Exception {
AudioInputStream audioInputStream = null;
URL audioSource = new File(resFile).toURL();
audioInputStream = AudioSystem.getAudioInputStream(audioSource);
AudioFormat format = audioInputStream.getFormat();
SourceDataLine line = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format);
line.start();
int bytesRead = 0;
byte[] data = new byte[32 * 1024];
try {
audioInputStream.mark(Integer.MAX_VALUE);
while(bytesRead != -1) {
bytesRead = audioInputStream.read(data, 0, data.length);
if(bytesRead >= 0) {
line.write(data, 0, bytesRead);
}
Thread.yield();
}
} finally {
line.drain();
line.close();
}
}
In order to be able to play OGG files as well, I downloaded Vorbis SPI and put the jar in the classpath. I tried with this sample ogg from Wikipedia. But it still doesn't work, it gives me an UnsupportedAudioFileException.
Do you know what I could be doing wrong?
Solution 1:[1]
Oops... turns out I didn't have all the dependencies in my classpath: tritonus_share.jar, jorbis-0.0.15.jar, jogg-0.0.7.jar.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cos64 |
