[mary-dev] A error that can interest you

Paulo Levi i30817 at gmail.com
Tue Oct 13 22:56:11 CEST 2009


In some linux systems i've been seeing a LineUnavailable exception. I
think i know why this happens:
JavaSound has hardware and software mixers. The hardware ones use OSS
and OSS needs exclusive access to the hardware.

On systems where PulseAudio is used Java sound using the hardware
mixers fails because the line is already in use by Pulse.
I'm going to use this code to try to work around that. I'm going to
tell you how it works later.

private SourceDataLine getSourceDataLine(AudioFormat format) {
        Exception audioException = null;
        try {
            DataLine.Info info = new
DataLine.Info(SourceDataLine.class, format);

            for (Mixer.Info mi : AudioSystem.getMixerInfo()) {
                SourceDataLine dataline = null;
                try {
                    Mixer mixer = AudioSystem.getMixer(mi);
                    dataline = (SourceDataLine) mixer.getLine(info);
                    dataline.open(format);
                    dataline.start();
                    return dataline;
                } catch (Exception e) {
                    audioException = e;
                }
                if (dataline != null) {
                    try {
                        dataline.close();
                    } catch (Exception e) {
                    }
                }
            }
        } catch (Exception e) {
            throw new IllegalStateException("Error trying to aquire
dataline.", e);
        }
        if(audioException == null){
            throw new IllegalStateException("Couldn't aquire a
dataline, this computer doesn't seem to have audio output?");
        }else{
            throw new IllegalStateException("Couldn't aquire a
dataline, probably because all are in use. Last
exception:",audioException);
        }
    }


More information about the Mary-dev mailing list