java-vorbis-support icon indicating copy to clipboard operation
java-vorbis-support copied to clipboard

Unsupported conversion exception

Open Valrog opened this issue 8 years ago • 3 comments
trafficstars

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.

Valrog avatar Jun 07 '17 14:06 Valrog

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.

Trilarion avatar Jun 08 '17 05:06 Trilarion

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.

Sample_Audio.zip

Valrog avatar Jun 08 '17 10:06 Valrog

Maybe i can fix this , reading the code.

goxr3plus avatar May 01 '19 09:05 goxr3plus