Music files not stopping even after closing browser
Hi, in my JApplet, I play music files when you click on a button. When I close the applet window in eclipse, the sound stops playing.
However, when I run my applet in a browser, the sound continues and keeps on going until the song finishes. I even included destroy() and stop() functions in which I end the music
Code:
public class birthday extends JApplet
{
....
JPanel songBoard;
JButton song1;
JButton song2;
JButton song3;
JButton song4;
AudioClip song;
URL songPath;
boolean isPlaying = false;
...
public void init()
{
songBoard = new JPanel();
songBoard.setLayout(new FlowLayout());
songBoard.setBounds(180, 50, 700, 500);
songBoard.setOpaque(true);
song1 = new JButton("In the End");
song2 = new JButton("What I've Done");
song3 = new JButton("New Divide");
song4 = new JButton("Somewhere I Belong");
song1.addActionListener(action);
song2.addActionListener(action);
song3.addActionListener(action);
song4.addActionListener(action);
songBoard.add(song1);
songBoard.add(song2);
songBoard.add(song3);
songBoard.add(song4);
pane.add(songBoard, new Integer(1)); //a JLayeredPane
...
}
private class ActionListenerClass implements ActionListener
{
@Override
public void actionPerformed(ActionEvent evt) {
if(evt.getSource() == song1)
{
song= getAudioClip(getDocumentBase(), "In The End.wav");
playSong();
}
else if(evt.getSource() == song2)
{
song = getAudioClip(getDocumentBase(), "What I've Done.wav");
playSong();
}
else if(evt.getSource() == song3)
{
song = getAudioClip(getDocumentBase(), "New Divide.wav");
playSong();
}
else if(evt.getSource() == song4)
{
song = getAudioClip(getDocumentBase(), "Somewhere I Belong.wav");
playSong();
}
}
}
public void playSong()
{
song.play();
isPlaying = true;
progress.setValue(50);
songBoard.setVisible(false);
}
public void destroy()
{
if(isPlaying)
song.stop();
}
public void stop()
{
if(isPlaying == true)
song.stop();
}