Option to play sound when rip completes

Closes #38
This commit is contained in:
4pr0n 2014-05-11 00:38:15 -07:00
parent 65f8bd2f3b
commit a1c46746ce
3 changed files with 35 additions and 1 deletions

View File

@ -104,6 +104,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
private static JButton configSaveDirButton;
private static JTextField configRetriesText;
private static JCheckBox configAutoupdateCheckbox;
private static JCheckBox configPlaySound;
private static TrayIcon trayIcon;
private static MenuItem trayMenuMain;
@ -166,6 +167,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
Utils.setConfigInteger("download.timeout", Integer.parseInt(configTimeoutText.getText()));
Utils.setConfigBoolean("clipboard.autorip", ClipboardUtils.getClipboardAutoRip());
Utils.setConfigBoolean("auto.update", configAutoupdateCheckbox.isSelected());
Utils.setConfigBoolean("play.sound", configPlaySound.isSelected());
saveHistory();
Utils.saveConfig();
}
@ -305,6 +307,9 @@ public class MainWindow implements Runnable, RipStatusHandler {
configAutoupdateCheckbox = new JCheckBox("Auto-update?", Utils.getConfigBoolean("auto.update", true));
configAutoupdateCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
configAutoupdateCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
configPlaySound = new JCheckBox("Sound when rip completes", Utils.getConfigBoolean("play.sound", false));
configPlaySound.setHorizontalAlignment(JCheckBox.RIGHT);
configPlaySound.setHorizontalTextPosition(JCheckBox.LEFT);
configSaveDirLabel = new JLabel();
try {
String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory()));
@ -323,7 +328,8 @@ public class MainWindow implements Runnable, RipStatusHandler {
gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc);
gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc);
gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc);
gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc);
gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc);
gbc.gridy = 0; pane.add(ripPanel, gbc);
@ -755,6 +761,9 @@ public class MainWindow implements Runnable, RipStatusHandler {
if (!historyListModel.contains(ripTextfield.getText())) {
historyListModel.addElement(ripTextfield.getText());
}
if (configPlaySound.isSelected()) {
Utils.playSound("camera.wav");
}
saveHistory();
ripButton.setVisible(true);
stopButton.setVisible(false);

View File

@ -12,6 +12,12 @@ import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;
@ -283,4 +289,23 @@ public class Utils {
}
return list;
}
public static void playSound(String filename) {
URL resource = ClassLoader.getSystemClassLoader().getResource(filename);
try {
final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
clip.addLineListener(new LineListener() {
@Override
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
clip.close();
}
}
});
clip.open(AudioSystem.getAudioInputStream(resource));
clip.start();
} catch (Exception e) {
logger.error("Failed to play sound " + filename, e);
}
}
}

Binary file not shown.