<Sound Dev> sound on Linux

Paulo Levi i30817 at gmail.com
Tue Oct 13 15:45:37 PDT 2009

I was just looking at this problem a while ago... opening the java
sound audio engine instead of the default one might be a solution.
Actually right now i'm using the method bellow, however, there are
still some errors on a test machine that exhibited errors before (but
no exception anymore) - the errors come in a Fedora (Pulse-Audio)
linux. Obviously if it can't open the mixer it will try to open the
java sound audio engine one - that should take take of one of the
errors java not playing, but still might cause the second - native
applications not playing.
Actually the guy that is running the tests for me in that machine
reports that audio is inaudible still, but no exception is raised if i
use this.

     * Lines can fail to open because they are already in use.
     * Java sound uses OSS and some linuxes are using pulseaudio.
     * OSS needs exclusive access to the line, and pulse audio
     * highjacks it. Try to open another line.
     * @param format
     * @return a open line
     * @throws IllegalStateException if it can't open a dataline for the
     * audioformat.
    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);
                    return dataline;
                } catch (Exception e) {
                    audioException = e;
                if (dataline != null) {
                    try {
                    } 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:",

More information about the sound-dev mailing list