aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/soundchan/LocalAudioManager.java
diff options
context:
space:
mode:
authorBrandon <bwaggone@umich.edu>2019-01-20 16:42:55 -0500
committerGitHub <noreply@github.com>2019-01-20 16:42:55 -0500
commit011c7d0637762c86c0da7375add64b64fb00713f (patch)
tree761cd2d09f1698e3f2fcc3d9374120232e08b79b /src/main/java/soundchan/LocalAudioManager.java
parentaa8c0e31584a046d7b9515f6bf1c191331d00333 (diff)
parent47ebae8b5085b7deed8fc10b69bc0f4be4d4e00d (diff)
downloadSoundChan-011c7d0637762c86c0da7375add64b64fb00713f.tar.gz
SoundChan-011c7d0637762c86c0da7375add64b64fb00713f.tar.bz2
SoundChan-011c7d0637762c86c0da7375add64b64fb00713f.zip
Merge pull request #10 from bwaggone/feature/sound-rescan
Feature/sound rescan
Diffstat (limited to 'src/main/java/soundchan/LocalAudioManager.java')
-rw-r--r--src/main/java/soundchan/LocalAudioManager.java52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/main/java/soundchan/LocalAudioManager.java b/src/main/java/soundchan/LocalAudioManager.java
index 28d25b9..ea5b317 100644
--- a/src/main/java/soundchan/LocalAudioManager.java
+++ b/src/main/java/soundchan/LocalAudioManager.java
@@ -17,11 +17,12 @@ public class LocalAudioManager {
public Map<String, String> filenameDict;
public Map<String, String> usernameDict;
private String filepath;
+ private String userSoundFilepath;
public LocalAudioManager(String filepath_in){
filepath = filepath_in;
- filenameDict = new HashMap<>();
- PopulateFiles();
+ userSoundFilepath = null;
+ filenameDict = PopulateFiles();
}
/**
@@ -31,10 +32,9 @@ public class LocalAudioManager {
*/
public LocalAudioManager(String filepath_in, String userSoundFile) {
filepath = filepath_in;
- filenameDict = new HashMap<>();
- usernameDict = new HashMap<>();
- PopulateFiles();
- MapUserAudio(userSoundFile);
+ userSoundFilepath = userSoundFile;
+ filenameDict = PopulateFiles();
+ usernameDict = MapUserAudio();
}
/**
@@ -90,31 +90,57 @@ public class LocalAudioManager {
channel.sendMessage(toPrint).queue();
}
- private void PopulateFiles(){
+ /**
+ * Updates the map of sound files
+ */
+ public void UpdateFiles() {
+ filenameDict = PopulateFiles();
+ }
+
+ /**
+ * Updates the map of usernames to sound files
+ */
+ public void UpdateUserAudio() {
+ if(userSoundFilepath != null | userSoundFilepath.contentEquals("")) {
+ usernameDict = MapUserAudio();
+ }
+ }
+
+ /**
+ * Creates a map of the sounds in the sound directory
+ * @return A map with the filename (without extension) is the key for the filename (with extension)
+ */
+ 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;
}
/**
* Reads in users and their respective sounds from file, then builds a map of users to the filenames. This assumes
* filenames for the sounds are valid, but doesn't check for them.
- * @param userSoundFile The file (with path if required) with listing of users and the sounds to play when they join
+ * @return A map with the usernames as the keys for the filename of the sound
*/
- private void MapUserAudio(String userSoundFile) {
- Properties userSoundProp = LoadProperties(userSoundFile);
+ private Map<String, String> MapUserAudio() {
+ Properties userSoundProp = LoadProperties(userSoundFilepath);
Set<String> users = userSoundProp.stringPropertyNames();
+
+ Map<String, String> userDict = new HashMap<>();
+
for(String user : users) {
String soundFile = userSoundProp.getProperty(user);
- usernameDict.put(user, soundFile);
+ userDict.put(user, soundFile);
}
-
+ return userDict;
}
/**