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]
# 1

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();

}

jacksonpaulsa at 2007-7-7 15:39:47 > top of Java-index,Other Topics,Java Game Development...
# 2
http://www.jsresources.org/examples/audio.html http://www.jsresources.org/examples/ClipPlayer.java.html
JTeena at 2007-7-7 15:39:47 > top of Java-index,Other Topics,Java Game Development...
# 3

I am able to use the Clip Interface to play sound from the command line but for some reason when I try to do the same thing from an Applet - the same code - doesn't work. Am I doing something wrong in migrating these codes into an Applet. Can sombody please show me how to write a Clip Interface that works in an Applet? Thank You.

TeferaKa at 2007-7-7 15:39:47 > top of Java-index,Other Topics,Java Game Development...
# 4
AudioClip also supports pre-loading.
hal2000@suna at 2007-7-7 15:39:47 > top of Java-index,Other Topics,Java Game Development...