Thank you for that reply. The code you linked to is very helpful for a number of things. However, if all someone wants to do is play a sound, there is a lot of extra info there.
For future reference if someone comes across this thread, I believe all the code that is needed just to play a sound is below. I am no java expert though and would appreciate if someone can confirm.
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import java.io.File;
private void playSound(File wavFile) throws JFException
{
try
{
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(wavFile);
AudioFormat af = audioInputStream.getFormat();
int nSize = (int) (af.getFrameSize() * audioInputStream.getFrameLength());
byte[] audio = new byte[nSize];
DataLine.Info info = new DataLine.Info(Clip.class, af, nSize);
audioInputStream.read(audio, 0, nSize);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(af, audio, 0, nSize);
clip.start();
}
catch (Exception e)
{
e.printStackTrace();
throw new JFException(e);
}
}
I am getting a warning on this line:
e.printStackTrace();
it's not coming up as an error, but only a warning. Not sure if its a big deal. The warning text says "Throwable.printStackTrace() should be removed"