我有以下方法来播放音频剪辑:
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();
}当我在Windows 7桌面平台(联想)上运行它时,它按预期工作。但是,在Windows 7笔记本电脑(Acer)上运行时,出现以下异常:
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)第62行是'AudioInputStream'语句。我不知道两个平台之间有什么区别,但我猜测笔记本电脑上必须存在一些Windows 7依赖项。有没有人有什么建议? TIA。