Just wondering if someone could she some light on this for me, i have an application for college which translates irish to english and vice versa, and the audio has to be done using threads. When i click play the audio plays, but when i change the word, and click play again, the audio plays both the previous audioclip and also the current simultaneously... Below is my code for the action and also the Audiopreloader class.. Thanks in advance
PlayButton event:
if (e.getSource() == playAudioBtn)
{
try {
soundURL = new URL("file:" + System.getProperty("user.dir") + "/" + outputLabel.getText() + ".wav");
}
catch (MalformedURLException e1)
{
}
System.out.println("Fetching Media "+ soundURL);
new MediaPreLoader(soundURL);
audioThread = new Thread() {
public void run() {
new MediaPreLoader(soundURL);
MediaPreLoader.currentMedia.play();
}
};
audioThread.start();
}
Media preLoader:
import java.applet.*;
import java.net.*;
public class MediaPreLoader extends Thread {
URL completeURL;
static AudioClip currentMedia;
public MediaPreLoader (URL mediaURL){
completeURL = mediaURL;
start();
}
public void run(){
currentMedia = Applet.newAudioClip(completeURL);
currentMedia.play();
}
}