aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/soundchan/LocalAudioManager.java
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2018-10-14 20:21:26 -0400
committerMatt Kohls <mattkohls13@gmail.com>2018-10-14 20:21:26 -0400
commit155bdfdffbae68f85cc971eb96ea432a6f4a736d (patch)
tree8cb669ff5702e4ebcb3adab779e1059c2cfd1c3a /src/main/java/soundchan/LocalAudioManager.java
parentf78dc260bc113e458020cfacaacd26fb4c2a4a27 (diff)
downloadSoundChan-155bdfdffbae68f85cc971eb96ea432a6f4a736d.tar.gz
SoundChan-155bdfdffbae68f85cc971eb96ea432a6f4a736d.tar.bz2
SoundChan-155bdfdffbae68f85cc971eb96ea432a6f4a736d.zip
Adding ability for sounds to be added/removed on the fly
This adds a watcher to the directory named in localAudio (currently doesn't check anything that may be in a child directory). Whenever a file is created/deleted/renamed, it has the LocalAudioManager update its sounds so they can be played.
Diffstat (limited to 'src/main/java/soundchan/LocalAudioManager.java')
-rw-r--r--src/main/java/soundchan/LocalAudioManager.java20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main/java/soundchan/LocalAudioManager.java b/src/main/java/soundchan/LocalAudioManager.java
index 4b16850..306b8dd 100644
--- a/src/main/java/soundchan/LocalAudioManager.java
+++ b/src/main/java/soundchan/LocalAudioManager.java
@@ -20,8 +20,7 @@ public class LocalAudioManager {
public LocalAudioManager(String filepath_in){
filepath = filepath_in;
- filenameDict = new HashMap<>();
- PopulateFiles();
+ filenameDict = PopulateFiles();
}
/**
@@ -31,9 +30,8 @@ public class LocalAudioManager {
*/
public LocalAudioManager(String filepath_in, String userSoundFile) {
filepath = filepath_in;
- filenameDict = new HashMap<>();
+ filenameDict = PopulateFiles();
usernameDict = new HashMap<>();
- PopulateFiles();
MapUserAudio(userSoundFile);
}
@@ -87,16 +85,26 @@ public class LocalAudioManager {
channel.sendMessage(toPrint).queue();
}
- private void PopulateFiles(){
+ /**
+ * Updates the map of sound files
+ */
+ public void UpdateFiles() {
+ filenameDict = PopulateFiles();
+ }
+
+ private Map<String, String> PopulateFiles(){
File folder = new File(filepath);
File[] listOfFiles = folder.listFiles();
+ Map<String, String> fileDict = new HashMap<>();
+
for (File file : listOfFiles) {
if (file.isFile()) {
String filename = file.getName();
- filenameDict.put(filename.substring(0, filename.indexOf('.')), filename);
+ fileDict.put(filename.substring(0, filename.indexOf('.')), filename);
}
}
+ return fileDict;
}
/**