I have a Java application whose UI relies heavily on audio. On Windows and OS X, everything works fine; on Linux, however, the application requires exclusive access to the sound device, a LineUnavailableException
is thrown and no sound is heard. I'm using Kubuntu 9.10.
This means that no other application can play audio while the program is running, and can't even be holding an audio device when the program starts. This is naturally unacceptable.
Here is the code I'm using to play audio:
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
this.wait((clip.getMicrosecondLength() / 1000) + 100);
clip.stop();
Am I doing something wrong? Is using Java to play audio in Linux a lost cause?