posted 19 years ago
I need to play a sound when a button is selected. I am using the following code to do it:
JRadioButton soundBT = new JRadioButton();
.
.
.
soundBT.addActionListener(new ActionListener() {
public void actionPerormed(ActionEvent e) {
if (soundBT.isSelected()) {
URL soundUrl = getClass().getResource(EOF_SOUND);
AudioClip audioClip = Applet.newAudioClip(soundUrl);
audioClip.play();
}
}
});
However, the sound is inconsistent. Sometimes it is played, other times it is played partially, and sometimes it is not played at all. Any suggestions would be helpfull. Thanks.
}