I am trying to add audio to a break clock and I have been trying to figure it out.. I want the user to select the audio file (wav or midi) when clicking the audio button then when the action happens (like an alarm) the audio file plays once.
Here is my code:
AudioClip song;
File fileName = null;
private AudioButtonHandler abHandler;
JButton cmdAudio = new JButton("Audio");
abHandler = new AudioButtonHandler();
cmdAudio.addActionListener(abHandler);
panel.add(cmdAudio);
public class AudioButtonHandler implements ActionListener
{
{
JFileChooser fc = new JFileChooser();
int result = fc.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION && result == JFileChooser.FILES_ONLY)
{
fileName = fc.getSelectedFile();
}
}
}
public class Sound
{
private URL songPath;
Sound(File fileName)
{
try
{
songPath = fileName.toURL();
song = AppletnewAudioClip(songPath);
}
catch(Exception e)
{
}
}
}
also I was using song.play(); as the call but it made the clock stop after activating the pop-up message..