Question

I have an AudioInputStream, and I want a FLAC AudioInputStream.

I am using the FlacEncoding.FLAC from the jflac library.

I added the mp3plugin.jar to the classpath to handle mp3.

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;

import org.kc7bfi.jflac.sound.spi.FlacEncoding;

public AudioInputStream getFlacStream(AudioInputStream ais) {
    FlacEncoding encoding = FlacEncoding.FLAC;
    AudioInputStream flacStream = AudioSystem.getAudioInputStream(encoding,
            ais);
    return flacStream;
}

but it gives error:

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported conversion: FLAC from MPEG2L3 22050.0 Hz, unknown bits per sample, mono, unknown frame size, unknown frame rate, 
    at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:876)
    at FlacConverter.getFlacStream(FlacConverter.java:43)
    at FlacConverter.getFlacBytes(FlacConverter.java:36)
    at FlacConverter.main(FlacConverter.java:25)

update:

when I call

AudioSystem.getTargetEncodings(ais.getFormat());

I get an array with only one encoding:

PCM_SIGNED
Was it helpful?

Solution

jflac currently only supports decoding from FLAC not encoding to FLAC.

I see there is a javaFlacEncoder project on sourceforge which might do what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top