samedi 20 décembre 2014

Java Detecing when sound stops

Hello I have a sound class for my application and it plays a certain sound when I tell it too. I want to be able to detect when the sound is finished playing so I can then play a different sound without them over lapping here is my sound class:



public class Sound {

public static final Sound cash = new Sound("/cash.wav");
public static final Sound snap = new Sound("/snap.wav");
public static final Sound disarm = new Sound("/disarm.wav");
public static final Sound tp = new Sound("/tp.wav");
public static final Sound select = new Sound("/selectBTN.wav");
public static final Sound scroll = new Sound("/btn.wav");
public static final Sound fire = new Sound("/fire2.wav");

private AudioClip c;

public Sound(String filename) {
try {
c = Applet.newAudioClip(Sound.class.getResource(filename));

} catch (Exception e) {
e.printStackTrace();
}
}

public void play() {
try {
new Thread() {
public void run() {
if (!title.mute) {

c.play();
}
}
}.start();
} catch (Exception e) {
e.printStackTrace();
}
}


}


then to play the sound I use this line of code:



Sound.cash.play();


How can I detect when the sound is finished playing


Aucun commentaire:

Enregistrer un commentaire