我在游戏中使用 Clips。剪辑播放正常,但经过一些“镜头”后,出现以下问题
线程“PulseAudio Eventloop Thread”java.lang.IllegalStateException 中的异常:在 org.classpath.icedtea.pulseaudio.EventLoop.run(EventLoop.java:133) 的 org.classpath.icedtea.pulseaudio.EventLoop.native_iterate(Native Method) ) 在 java.lang.Thread.run(Thread.java:724)
我的代码:
public static Clip[] sounds;
...
sounds = new Clip[3];
sounds[0] = getClip("gun.wav");
sounds[1] = getClip("click.wav");
sounds[2] = getClip("over.wav");
...
private void playSound(Clip clp) {
final Clip clip = clp;
Runnable soundPlayer = new Runnable() {
@Override
public void run() {
try {
if(clip.isActive() || clip.isRunning()) clip.stop();
clip.setMicrosecondPosition(0);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
};
new Thread(soundPlayer).start();
}
public void shoot() { //runs when space is clicked
if(canShoot) playSound(sounds[0]);
}