|
6 | 6 | import org.jetbrains.annotations.Nullable; |
7 | 7 | import xyz.gianlu.librespot.common.Utils; |
8 | 8 | import xyz.gianlu.librespot.core.Session; |
| 9 | +import xyz.gianlu.librespot.player.PlayerRunner; |
9 | 10 | import xyz.gianlu.librespot.player.StreamFeeder; |
10 | 11 |
|
11 | 12 | import java.io.File; |
@@ -61,6 +62,14 @@ private float getFloat(@NotNull String key, float fallback) { |
61 | 62 | } |
62 | 63 | } |
63 | 64 |
|
| 65 | + private int getInt(@NotNull String key, int fallback) { |
| 66 | + try { |
| 67 | + return Integer.parseInt(properties.getProperty(key, String.valueOf(fallback))); |
| 68 | + } catch (NumberFormatException ex) { |
| 69 | + return fallback; |
| 70 | + } |
| 71 | + } |
| 72 | + |
64 | 73 | @Contract("_, _, !null -> !null") |
65 | 74 | private <E extends Enum<E>> E getEnum(@NotNull Class<E> clazz, @NotNull String key, @Nullable E fallback) { |
66 | 75 | String val = properties.getProperty(key, null); |
@@ -126,6 +135,17 @@ public boolean logAvailableMixers() { |
126 | 135 | return getBoolean("player.logAvailableMixers", defaults.logAvailableMixers()); |
127 | 136 | } |
128 | 137 |
|
| 138 | + @Override |
| 139 | + public int initialVolume() { |
| 140 | + int vol = getInt("player.initialVolume", defaults.initialVolume()); |
| 141 | + if (vol < 0 || vol > PlayerRunner.VOLUME_MAX) { |
| 142 | + LOGGER.warn("Invalid volume: " + vol); |
| 143 | + return defaults.initialVolume(); |
| 144 | + } else { |
| 145 | + return vol; |
| 146 | + } |
| 147 | + } |
| 148 | + |
129 | 149 | @Override |
130 | 150 | public @Nullable String deviceName() { |
131 | 151 | return properties.getProperty("deviceName", null); |
|
0 commit comments