Hello I have kind a weird problem.
import java.io.*;
import javax.sound.sampled.*;
public class Sound
{
public void newGame()
{
AudioInputStream audioInputStream = null;
try
{
audioInputStream = AudioSystem.getAudioInputStream(getClass().getClassLoader().getResource("files" + File.separator + "newGame.wav"));
AudioFormat audioFormat = audioInputStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, audioFormat);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(audioInputStream);
clip.start();
}
catch (UnsupportedAudioFileException | IOException | LineUnavailableException e)
{
System.out.println(e.getMessage());
System.exit(-1);
}
finally
{
try
{
if(audioInputStream != null)
{
audioInputStream.close();
}
}
catch (IOException e)
{
System.out.println(e.getMessage());
System.exit(-1);
}
}
}
}
I use this code to play sound at the beggining of the new game.
When I run my project from Netbeans IDE everything works just fine but when I build the project and I run it by clicking on the .jar file I begin a new game and the sound is played just for like a half second instead of four seconds. I have no idea why.