Skip to content

Commit 4f82817

Browse files
committed
Set initial volume
1 parent 7a17d64 commit 4f82817

6 files changed

Lines changed: 39 additions & 4 deletions

File tree

conf.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ preload.enabled=true
2626
player.preferredAudioQuality=VORBIS_160
2727
# Normalisation pregain
2828
player.normalisationPregain=0
29+
# Initial volume (0-65536)
30+
player.initialVolume=65536
2931
# Default unshuffle behaviour (can't unshuffle if client is loaded with shuffled playlist)
3032
player.defaultUnshuffleBehaviour=false
3133
# Log available mixers

core/src/main/java/xyz/gianlu/librespot/DefaultConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.jetbrains.annotations.Nullable;
55
import xyz.gianlu.librespot.core.Session;
6+
import xyz.gianlu.librespot.player.PlayerRunner;
67
import xyz.gianlu.librespot.player.StreamFeeder;
78

89
import java.io.File;
@@ -42,6 +43,11 @@ public boolean logAvailableMixers() {
4243
return true;
4344
}
4445

46+
@Override
47+
public int initialVolume() {
48+
return PlayerRunner.VOLUME_MAX;
49+
}
50+
4551
@Override
4652
public boolean preloadEnabled() {
4753
return true;

core/src/main/java/xyz/gianlu/librespot/FileConfiguration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.jetbrains.annotations.Nullable;
77
import xyz.gianlu.librespot.common.Utils;
88
import xyz.gianlu.librespot.core.Session;
9+
import xyz.gianlu.librespot.player.PlayerRunner;
910
import xyz.gianlu.librespot.player.StreamFeeder;
1011

1112
import java.io.File;
@@ -61,6 +62,14 @@ private float getFloat(@NotNull String key, float fallback) {
6162
}
6263
}
6364

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+
6473
@Contract("_, _, !null -> !null")
6574
private <E extends Enum<E>> E getEnum(@NotNull Class<E> clazz, @NotNull String key, @Nullable E fallback) {
6675
String val = properties.getProperty(key, null);
@@ -126,6 +135,17 @@ public boolean logAvailableMixers() {
126135
return getBoolean("player.logAvailableMixers", defaults.logAvailableMixers());
127136
}
128137

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+
129149
@Override
130150
public @Nullable String deviceName() {
131151
return properties.getProperty("deviceName", null);

core/src/main/java/xyz/gianlu/librespot/core/Session.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ private void reconnect() {
394394
}
395395
}
396396

397+
@NotNull
398+
public AbsConfiguration conf() {
399+
return inner.configuration;
400+
}
401+
397402
public enum DeviceType {
398403
Unknown(0, "unknown"),
399404
Computer(1, "computer"),

core/src/main/java/xyz/gianlu/librespot/player/Player.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ public interface Configuration {
387387
String[] mixerSearchKeywords();
388388

389389
boolean logAvailableMixers();
390+
391+
int initialVolume();
390392
}
391393

392394
private class StateWrapper {

core/src/main/java/xyz/gianlu/librespot/spirc/SpotifyIrc.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import xyz.gianlu.librespot.mercury.MercuryClient;
1111
import xyz.gianlu.librespot.mercury.RawMercuryRequest;
1212
import xyz.gianlu.librespot.mercury.SubListener;
13+
import xyz.gianlu.librespot.player.Player;
1314
import xyz.gianlu.librespot.player.PlayerRunner;
1415

1516
import java.io.Closeable;
@@ -32,21 +33,20 @@ public class SpotifyIrc implements Closeable {
3233
public SpotifyIrc(@NotNull Session session) {
3334
this.session = session;
3435
this.uri = String.format("hm://remote/user/%s/", session.apWelcome().getCanonicalUsername());
35-
this.deviceState = initializeDeviceState();
36+
this.deviceState = initializeDeviceState(session.conf());
3637
}
3738

3839
public void subscribe() throws IOException, IrcException, MercuryClient.PubSubException {
3940
session.mercury().subscribe(uri, internalListener = new SpircListener());
40-
4141
send(Spirc.MessageType.kMessageTypeHello);
4242
}
4343

4444
@NotNull
45-
private Spirc.DeviceState.Builder initializeDeviceState() {
45+
private Spirc.DeviceState.Builder initializeDeviceState(@NotNull Player.Configuration conf) {
4646
return Spirc.DeviceState.newBuilder()
4747
.setCanPlay(true)
4848
.setIsActive(false)
49-
.setVolume(PlayerRunner.VOLUME_MAX)
49+
.setVolume(conf.initialVolume())
5050
.setName(session.deviceName())
5151
.setSwVersion(Version.versionString())
5252
.addCapabilities(Spirc.Capability.newBuilder()

0 commit comments

Comments
 (0)