3

I'm working on in a java project that helps people to learn the location of countries in the map.

The program plays a .wav sound file when the mouse passes over an object and works perfectly running in Windows but today I tried to so the same in Ubuntu and the program throws the next Exception:

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.

This is the method that plays the 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);            
    }
}

Could anyone tell me how can I solve this issue?

I've been searching a lot but I haven't found a clear answer that help me.

I think there are some important things I didn't specified...

The exception I mentioned before is thrown when the event mouseEntered is fired but this is a little strange because the program doesn't have any problems at first glance. The sound in reproduced correctly at the beginning and the exception is thrown after I pass the mouse over some of the objects.

Sandoval0992
  • 1,307
  • 3
  • 18
  • 24
  • This really has nothing to do with the tags I removed. I added the Java Sound tag. – Andrew Thompson Jan 06 '15 at 06:44
  • Can you upload the sound somewhere? I think I may be able to figure out how to play it, but need to experiment. – Andrew Thompson Jan 06 '15 at 06:45
  • Do you think this is related? http://stackoverflow.com/questions/27703586/cannot-load-sound-later-during-runtime On what line does the error occur? on "sound.start();"? or when you attempt to open the file? Is the "new File(path)" part working? Odd that two instances of this error are happening. The file format listed in the error is supposed to be supported by Java. What version of Java are you running? What source? (e.g., Oracle/OpenJDK/??) – Phil Freihofner Jan 07 '15 at 01:44
  • This is the information I got from executing the command java -version Java(TM) SE Runtime Environment (build 1.7.0_72-b14) Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode) The question in the link you shared above is very similar to mine. I added some details to my question. – Sandoval0992 Jan 07 '15 at 02:53
  • I'm not clear what is causing the error. It works in Windows but not Ubuntu? Do both play through the same sound card? Also, I still do not understand when the error is thrown. I take it the error is passed up to the mouseEntered code, but which of the three lines is causing the error? You could put some System.out.println() statements in to try and isolate which line. Another thing, for what you are doing, using SourceDataLine instead of Clip is more correct, since you are destroying the Clip after each mouseEntered. If it works for some sound files and not others, check their formats! – Phil Freihofner Jan 07 '15 at 23:26

1 Answers1

-2

Why don't you try taking the file and getting its absolute path, then storing the return value as your path variable. Then, use the path to get your audio input stream. However, the exception thrown may not belong to this snippet shown at all, I'd believe, if you handled conversion of file formats in your app. I'd suggest (if you did the extra handling) that you check for supported lines before using an available one. This way, you avoid such an error.

aburime gregory
  • 38
  • 1
  • 1
  • 8