I've been racking my brains trying to get this looping wav to pause upon a second click, where am i going wrong?
private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {
JToggleButton btn = (JToggleButton) evt.getSource();
if (btn.isSelected()) {
try {
String soundName = "yourSound.wav";
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(new File(soundName).getAbsoluteFile());
} catch (UnsupportedAudioFileException | IOException ex) {
Logger.getLogger(GEN.class.getName()).log(Level.SEVERE, null, ex);
}
Clip clip = null;
try {
clip = AudioSystem.getClip();
} catch (LineUnavailableException ex) {
Logger.getLogger(GEN.class.getName()).log(Level.SEVERE, null, ex);
}
clip.open(audioInputStream);
clip.start();
clip.loop(100);
} catch (LineUnavailableException | IOException ex) {
Logger.getLogger(GEN.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
try {
}