Ich habe nichts geändert und jetzt funktioniert es manchmal, aber manchmal löst es eine IllegalArgumentException aus:
< pre class="lang-none Prettyprint-override">
Code: Select all
java.lang.IllegalArgumentException: No line matching interface Clip supporting format PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian is supported.
at java.desktop/javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:423)
at java.desktop/javax.sound.sampled.AudioSystem.getClip(AudioSystem.java:459)
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:75)
Code: Select all
public synchronized void playSound (String path) {
try {
File file = new File(path);
SoundPlayer sp = new SoundPlayer(file);
sp.start();
} catch (Exception e) {
e.printStackTrace();
}
}
class SoundPlayer extends Thread {
private File soundFile;
public SoundPlayer (File soundFile) {
this.soundFile = soundFile;
}
@Override
public void run () {
try {
if (clip != null && clip.isRunning()) {
clip.stop();
}
AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile);
clip = AudioSystem.getClip();
clip.open(ais);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}