Skip to content

Commit c3a7a11

Browse files
committed
Fixed #239
1 parent 44e33a1 commit c3a7a11

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/dealer/ApiClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ public Response send(@NotNull String method, @NotNull String suffix, @Nullable H
101101
public void putConnectState(@NotNull String connectionId, @NotNull Connect.PutStateRequest proto) throws IOException, MercuryClient.MercuryException {
102102
try (Response resp = send("PUT", "/connect-state/v1/devices/" + session.deviceId(), new Headers.Builder()
103103
.add("X-Spotify-Connection-Id", connectionId).build(), protoBody(proto), 5 /* We want this to succeed */)) {
104-
if (resp.code() != 200)
105-
LOGGER.warn("PUT {} returned {}. {headers: {}}", resp.request().url(), resp.code(), resp.headers());
104+
if (resp.code() == 413)
105+
LOGGER.warn("PUT state payload is too large: {} bytes uncompressed.", proto.getSerializedSize());
106+
else if (resp.code() != 200)
107+
LOGGER.warn("PUT state returned {}. {headers: {}}", resp.code(), resp.headers());
106108
}
107109
}
108110

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ private static class PlayableIdWithIndex {
858858
}
859859

860860
private class TracksKeeper {
861+
private static final int MAX_PREV_TRACKS = 16;
862+
private static final int MAX_NEXT_TRACKS = 48;
861863
private final LinkedList<ContextTrack> queue = new LinkedList<>();
862864
private final List<ContextTrack> tracks = new ArrayList<>();
863865
private final FisherYatesShuffle<ContextTrack> shuffle = new FisherYatesShuffle<>(session.random());
@@ -917,14 +919,14 @@ private void updatePrevNextTracks() {
917919
int index = getCurrentTrackIndex();
918920

919921
state.clearPrevTracks();
920-
for (int i = 0; i < index; i++)
922+
for (int i = Math.max(0, index - MAX_PREV_TRACKS); i < index; i++)
921923
state.addPrevTracks(ProtoUtils.convertToProvidedTrack(tracks.get(i)));
922924

923925
state.clearNextTracks();
924926
for (ContextTrack track : queue)
925927
state.addNextTracks(ProtoUtils.convertToProvidedTrack(track));
926928

927-
for (int i = index + 1; i < tracks.size(); i++)
929+
for (int i = index + 1; i < Math.min(tracks.size(), index + 1 + MAX_NEXT_TRACKS); i++)
928930
state.addNextTracks(ProtoUtils.convertToProvidedTrack(tracks.get(i)));
929931
}
930932

0 commit comments

Comments
 (0)