playing sound files by Clip interface !
i'm writting a game that consists of some threads
for handling graphical animations.
it causes the sounds of the game played with the
noticable delay.(i use AudioClip mehtods).
someone said me use Clip interface that is
quiker than AudioClip method beacause of pre-loading
sound data.
can u send me a (or afew) source code about Clip
interface?(play a sound file by this interface)
thank you very much.
[465 byte] By [
superJa] at [2007-9-27 23:27:10]

you could try something like:
try {
javax.sound.sampled.AudioInputStream audioInputStream = javax.sound.sampled.AudioSystem.getAudioInputStream(getClass().getResource("sound.wav"));
if (audioInputStream == null) System.err.println("Something wrong.");
final javax.sound.sampled.Clip clip = (javax.sound.sampled.Clip) javax.sound.sampled.AudioSystem.getLine(new javax.sound.sampled.DataLine.Info(javax.sound.sampled.Clip.class, audioInputStream.getFormat()));
clip.addLineListener(new javax.sound.sampled.LineListener() {
public void update(javax.sound.sampled.LineEvent evt) {
if (evt.getType() == javax.sound.sampled.LineEvent.Type.STOP) {
clip.stop();
clip.setMicrosecondPosition(0);
}
}
});
clip.open(audioInputStream);
clip.start();
clip.close();
}
catch (Exception e) {
e.printStackTrace();
}