How to check if an audio clip is finished

Hello

Currently I have the following code :

java.applet.AudioClip sound =null;

try

{

String userdir= System.getProperties().getProperty("user.dir") ;

java.io.File myfile =new java.io.File(userdir+audiofile);

java.net.URL url = myfile.toURL();

sound = java.applet.Applet.newAudioClip(url);

sound.play();

}

catch (Exception io){/* ignore */}

/* continue to work while music is playing */

--

--

It works fine, however, I'd like to check in another thread whether this clip is over. Is there any way to do this ?

[935 byte] By [martinelligegea] at [2007-11-26 18:33:53]
# 1

You have two options as I can see.

Option 1: Check sound thread during playing back.

sound = java.applet.Applet.newAudioClip(url) will start a thread named 'Java Sound Event Dispatcher' This thread lasts until the entire application exists.

sound.play() starts another thread which is doing the solid playback. It will end 2-4 seconds after the clip ends. It is named 'Direct Clip'

Option 2: Use javax.sound.sampled.Clip that offers isRunning() method.

rexyounga at 2007-7-9 6:07:59 > top of Java-index,Security,Cryptography...
# 2
Thanks a lot.
martinelligegea at 2007-7-9 6:07:59 > top of Java-index,Security,Cryptography...
# 3
Sorry it's still me !I tried to find a way to check whether a thread is still alive. I haven't found (except if I created the Thread instance myself)many thanks for anwsering.
martinelligegea at 2007-7-9 6:07:59 > top of Java-index,Security,Cryptography...