0

I have this slightly altered a sound manager from another question How can I play sound in Java?. Here it is:

public static synchronized void playSound(final String url)
{
    new Thread(new Runnable()
    {
        public void run()
        {
            try
            {
                Clip clip = AudioSystem.getClip();
                AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("sound/" + url));
                clip.open(inputStream);
                clip.start();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    }).start();
}

Whenever I call this method I get a javax.sound.sampled.LineUnavailableException in the clip.open(inputStream);. What can I do to repair it? Why does it not work?

Community
  • 1
  • 1
rdelfin
  • 819
  • 2
  • 13
  • 31
  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Why is the `String` argument called `url` when it is a relative file path? 3) *"Why does it not work?"* Why would you expect JavaSound to be able to open `resume.doc` ..oh, my bad, you had not at any point indicated what the value of the `String` was. See point (1) 4) Upload the file that cannot be opened, and provide a link. – Andrew Thompson Mar 15 '12 at 14:57
  • This is just a method I use. When I call it form a non-static context. I use a file called Song1. I call it like this: playSound("songs/Song3.wav");. It exists and is there. – rdelfin Mar 15 '12 at 16:03
  • I don't know who you are replying to, but since it is obviously not me, good luck with it. – Andrew Thompson Mar 15 '12 at 16:17

0 Answers0