I have the following method to play audio clips:
public static synchronized void playSound(final String path) {
new Thread(new Runnable() {
// The wrapper thread is unnecessary, unless it blocks on the
// Clip finishing; see comments.
public void run() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(
this.getClass().getClassLoader().getResourceAsStream(path));
clip.open(inputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
while (runThread) {
Thread.sleep(5000);
}
clip.stop();
}
catch (Exception e) {
System.err.println("Audio clip error: "+e.getMessage());
e.printStackTrace();
}
}
}).start();
}
When I run this on a Windows 7 desktop platform (Lenovo), it works as expected. However, when run on a windows 7 laptop (Acer), I get the following exception:
java.lang.NullPointerException
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at StokerMonitor.Alerts$1.run(Alerts.java:62)
at java.lang.Thread.run(Unknown Source)
Line 62 is the 'AudioInputStream' statement. I don't know what the difference is between the 2 platforms but I am guessing there must be some Windows 7 dependency that is missing on the laptop. Does anyone have any suggestions? TIA.