From a1c46746cec4f5ecac60cdc248b0bda41d926eda Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Sun, 11 May 2014 00:38:15 -0700 Subject: [PATCH] Option to play sound when rip completes Closes #38 --- .../com/rarchives/ripme/ui/MainWindow.java | 11 +++++++- .../java/com/rarchives/ripme/utils/Utils.java | 25 ++++++++++++++++++ src/main/resources/camera.wav | Bin 0 -> 5134 bytes 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/camera.wav diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 682b8251..ff719990 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -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); diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index a4ed8ad7..1914ff23 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -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); + } + } } \ No newline at end of file diff --git a/src/main/resources/camera.wav b/src/main/resources/camera.wav new file mode 100644 index 0000000000000000000000000000000000000000..617e0f03f802559268e4ef31d294e35f53344cd1 GIT binary patch literal 5134 zcmZ8ke}rvGe(wz%^H=OjY>corOspr5Wej8Ac=UAirdMlv)Ap|G%3a5vIUG5wq!dN1 zQp!}6R4U3AWll~UP8^53u3TEv(YEvA@o3(@c=8w{^Virh3`-38YlZ3k)V=*?S8nTb z&#fQdU-kWdKHvJQ?|$byzyC*jdp~%4c3AzGed8;8dwXBP-&g;9Z~OnHy;t_if)&5~ z!@a#*%)N2HxSzkZFm zn{J;z|McV)HnP3F{pYv0x1T@QyZ5l-pWS}A`Skk!-X2kpSJ%nA=5^KTO-dm81+xTPMt_4y3W?X|a`zVL5;a+|(+^~vq$w>L%kP#!#-_0M{v z=Vz}yaIaS7lW5%BI1zXoSMT?M&DeA`UXPnj^W}o4*vYz~LN-Lyh6ye>i?x(yUg>!= zXHl``v=9%Mrh9a~Y0T0!R5z=%>8&9|FPL>#?P_F;!USzL%6S(hiK^{fQ!bmvP}>e& z@cx7pq4iW78&go_%*0VR%5>uOvQgb-)W-9M6NYnXIbRke7+BZp&=4w}WA#mYN>A$CR6ELoVs7=x&a zBO5n;n<%9OsbS0*G;10ree_bg&@@uQ2gi-oI7ixcgOL^Qq@tYbZXHa`N}-c!*Vc%N zvfx`IOfs_JQkf7X^O}=ZM`EQ#=1J0#UV83?uTO0^8D@y#Gzp^YGMJR=ZAzFgu=gP$B4U8?BTTwg7ng}GQZH+gKFzY>xQA`@^yrwl*D*4nJg)C7z zIA`HgV%i(8kOQ1qtaCz2f%rHJ$&5-w0-=Qjgjh?XnO5EeW34e#Ssx5EGOI&0QY%TN zwcZ*n7{_kqyC@oNVLJ)2^;|SYwIkxAtH#eYxNSU0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