I've been trying to create a functioning mute button in swing. On start up a clip plays in my application. There is a button that (is supposed) to allow the user to stop the music. What am I doing wrong?
This is the code from my main method.
try {
File file = new File("Sounds/MenuMusic.wav"); // src is the location of the file
AudioInputStream stream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(stream);
clip.start();
if(mute==true){
clip.stop();
}
} catch (Exception e) {
e.printStackTrace();
}
And this is the action listener on my mute button.
btnSound.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mute=true;
}
});