Application now remembers the last value that volume was set to.
This commit is contained in:
parent
c7eb7fd024
commit
9164dff257
@ -19,6 +19,7 @@ public final class ConfigManager {
|
||||
private static final String foldersKey = "libraryFolders";
|
||||
private static final String databaseKey = "databaseDir";
|
||||
private static final String libraryDisplayKey = "libraryDisplayKey";
|
||||
private static final String lastVolumeKey = "volume";
|
||||
|
||||
/**
|
||||
* @return List of directories used for music library indexing.
|
||||
@ -92,4 +93,24 @@ public final class ConfigManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLastVolume(){
|
||||
try (FileInputStream inputStream = new FileInputStream(propertiesFile)) {
|
||||
librarySettings.load(inputStream);
|
||||
if (librarySettings.containsKey(lastVolumeKey)) {
|
||||
return Integer.parseInt(librarySettings.getProperty(lastVolumeKey));
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
|
||||
public static void setLastVolume(Integer index){
|
||||
librarySettings.setProperty(lastVolumeKey, index.toString());
|
||||
try(FileWriter fileWriter = new FileWriter(settingsFilename)){
|
||||
librarySettings.store(fileWriter, "");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -396,6 +396,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
volumeSlider.setMajorTickSpacing(20);
|
||||
volumeSlider.setMinorTickSpacing(10);
|
||||
volumeSlider.setPaintTicks(true);
|
||||
player.setVolume(ConfigManager.getLastVolume());
|
||||
volumeSlider.setValue(player.getVolume());
|
||||
panel.add(volumeSlider);
|
||||
JLabel volumeValue = new JLabel();
|
||||
@ -403,6 +404,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
volumeSlider.addChangeListener(e -> {
|
||||
player.setVolume(((JSlider) e.getSource()).getValue());
|
||||
volumeValue.setText(String.format("%d%%", player.getVolume()));
|
||||
ConfigManager.setLastVolume(player.getVolume());
|
||||
});
|
||||
panel.add(volumeValue);
|
||||
return panel;
|
||||
|
Loading…
Reference in New Issue
Block a user