Black Magic
Black Magic

Reputation: 2766

Clean and build, but my audio file is gone

I have a little question, I am building an app with the swing builder in Netbeans(note: it is Java). In this app I use an audio file I put in the main project folder, but when I start the jar, the audio file is not working, as if it's not included. Does anyone know how I can fix this?

Any help will be greatly appreciated, Black Magic

Upvotes: 1

Views: 60

Answers (1)

porterjr
porterjr

Reputation: 102

make sure that you have audio files in folder with jar and that path is correct. I used this method to play sounds:

public static synchronized void playSound(final File file) 
{
new Thread(new Runnable() 
{ 
    @Override
  public void run() 
  {
    try 
    {

      AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
      Clip clip = AudioSystem.getClip();
      clip.open(inputStream);
      clip.start(); 
    } catch (Exception e) 
    {

      System.err.println(e.getMessage());
    }
  }
}
        )
        .start();
}

In code i play sound using: playSound(new File("sounds/noise.wav"));

So i place my folder with noise.wav in folder with *.jar and it all works.

Upvotes: 1

Related Questions