Running sounds in succession
I have been trying to get some code together that will play one sound, and when that sound is done, play another sound but I have been unable to do so. I was hoping that someone here could point out the error in my logic and or code so that I can get it running.
//The calling method
private void playSound(String soundString)
{
try
{
Clip theClip = getClip(getURL(soundString));
SoundThread st = new SoundThread(theClip, 0);
st.playSound();
while (st.isDonePlaying() == false)
{
Thread.sleep(20);
}
} catch (Exception ex)
{
ex.printStackTrace();
}
}
//The sounds thread class
import javax.sound.sampled.*;
public class SoundThread extends Thread
{
private Clip soundClip = null;
private int soundIndex = 0;
private int loopCount = 0;
private boolean donePlaying = false;
public SoundThread(Clip clip, int index)
{
soundIndex = index;
soundClip = clip;
soundClip.stop();
soundClip.flush();
soundClip.setFramePosition(0);
soundClip.setLoopPoints(0, -1);
setPriority(Thread.MIN_PRIORITY);
}
public void playSound()
{
loopCount = 0;
start();
}
public void loopSound()
{
loopCount = Clip.LOOP_CONTINUOUSLY;
start();
}
public void stopSound()
{
soundClip.stop();
soundClip.flush();
soundClip.setFramePosition(0);
donePlaying = true;
}
public int getSoundIndex()
{
return soundIndex;
}
public boolean isDonePlaying()
{
return donePlaying;
}
public void run()
{
soundClip.loop(loopCount);
donePlaying = true;
}
}

