Javax.sound.sampled.LineUnavailableException

I am working on a java project that helps people find out the location of countries on a map.

The program plays a .wav sound file when the mouse passes over an object and works fine on Windows, but today I tried to do the same on Ubuntu and the program throws the following exception:

javax.sound.sampled.LineUnavailableException: Line formatted as PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes / frame, little endian not supported.

This is the method that plays sound.

public void playSound(String audioName){
    String path="src/audio/"+audioName+".wav";
    try{
        Clip sound=AudioSystem.getClip();
        sound.open(AudioSystem.getAudioInputStream(new File(path)));
        sound.start();            
    } catch(Exception e){
        JOptionPane.showMessageDialog(null,e);            
    }
}

      

Can anyone tell me how I can solve this problem?

I searched a lot, but I didn't find a clear answer that helped me.

I think there are some important things that I have not indicated ...

The exception that I mentioned earlier is thrown when the mouseEntered event fires, but this is a bit strange because at first glance the program has no problem. The sound plays correctly at the beginning and an exception is thrown after I pass the mouse over some objects.

+3


source to share


1 answer


Why don't you try to take the file and get its absolute path, and then store the return value as a path variable. Then use the path to get the audio input stream. However, the exception may not belong to this snippet shown at all, I suppose if you were to handle converting file formats in your application. I would suggest (if you've done some additional processing) that you check for supported strings before using the available one. This way you avoid such a mistake.



0


source







All Articles