• Post Reply Bookmark Topic Watch Topic
  • New Topic

playing sounds when button is pressed

 
Nadinha Jovan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!