Playing sound each time mouse is clicked (not working)
Hey guys, I'm really stumped. I have a chat program and figured it'd be nice to add sound alerts for new messages, but it's not playing sound at all now.
Code :
private class AudioClip extends Thread implements ActionListener{
private InputStream in;
private AudioStream as;
public void run(){
//Open audio stream
try{
in = new FileInputStream("alert.wav");
as = new AudioStream(in);
AudioPlayer.player.start(as);
Timer time = new Timer(5000, this);
time.setRepeats(false);
time.start();
}catch(FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent event) {
AudioPlayer.player.stop(as);
}
}
This is in the chat portion and happens each time a message pops up:
Code :
if(playAudio){
new AudioClip();
}
EDIT: Got it! I was in a hurry and forgot '.start()' haha