java-vorbis-support
java-vorbis-support copied to clipboard
Unsupported conversion exception
Greetings, I've used this project to extend the functionality of JavaFX so that it supports the playback of Ogg files. I'm using Clip to play files instead of a SourceDataLine. However, I cannot play every Ogg file and I get the following error.
IllegalArgumentException: Unsupported conversion: PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian from VORBISENC 48000.0 Hz, unknown bits per sample, mono, 1 bytes/frame, 10000.0 frames/second
Here is my play method.
public void playAudio() {
try {
File audioFile = getAudioFile();
if (!audioFile.exists()) {
logger.error("No file to play!");
return;
}
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(audioFile);
if (audioInputStream == null) {
logger.error("No file stream to play!");
return;
}
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 16000f, 16, 1, 2, 16000f, false);
AudioInputStream convertedAudioInputStream = AudioSystem.getAudioInputStream(format, audioInputStream);
DataLine.Info info = new DataLine.Info(Clip.class, format);
clip = (Clip) AudioSystem.getLine(info);
clip.addLineListener(this);
clip.open(convertedAudioInputStream);
this.playCompleted = false;
clip.start();
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException ex) {
logger.error(StackTraceHelper.getStackTrace(ex));
} catch (Throwable ex) {
logger.error(StackTraceHelper.getStackTrace(ex));
}
}
Files differ in Sample rate and Bitrate. Those who can be played have
Sample rate: 16000 Hz
Bitrate: 48 kbps
Those who cannot be played have
Sample rate: 48000 Hz
Bitrate: 80 kbps
All are encoded with Vorbis and have a Mono channel.
I'm not actively working on the project anymore. Maybe someone else could help.
A complete stacktrace of the exception and maybe a very short example ogg file would be nice to have.
Here is the complete stack trace.
Unsupported conversion: PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian from VORBISENC 48000.0 Hz, unknown bits per sample, mono, 1 bytes/frame, 6000.0 frames/second,
java.lang.IllegalArgumentException: Unsupported conversion: PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian from VORBISENC 48000.0 Hz, unknown bits per sample, mono, 1 bytes/frame, 6000.0 frames/second,
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:974)
at test.audioplayerdemo.AudioPlayerManager.play(AudioPlayerManager.java:58)
at test.audioplayerdemo.FXMLController.lambda$handlePlay$0(FXMLController.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Here are the sample audio files. File Audio_Sample_16kHz_48kbps works fine, the other two throw the exception.
Maybe i can fix this , reading the code.