Skip to content

Commit

Permalink
Fixed #239
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Jun 25, 2020
1 parent 44e33a1 commit c3a7a11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions core/src/main/java/xyz/gianlu/librespot/dealer/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ public Response send(@NotNull String method, @NotNull String suffix, @Nullable H
public void putConnectState(@NotNull String connectionId, @NotNull Connect.PutStateRequest proto) throws IOException, MercuryClient.MercuryException {
try (Response resp = send("PUT", "/connect-state/v1/devices/" + session.deviceId(), new Headers.Builder()
.add("X-Spotify-Connection-Id", connectionId).build(), protoBody(proto), 5 /* We want this to succeed */)) {
if (resp.code() != 200)
LOGGER.warn("PUT {} returned {}. {headers: {}}", resp.request().url(), resp.code(), resp.headers());
if (resp.code() == 413)
LOGGER.warn("PUT state payload is too large: {} bytes uncompressed.", proto.getSerializedSize());
else if (resp.code() != 200)
LOGGER.warn("PUT state returned {}. {headers: {}}", resp.code(), resp.headers());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ private static class PlayableIdWithIndex {
}

private class TracksKeeper {
private static final int MAX_PREV_TRACKS = 16;
private static final int MAX_NEXT_TRACKS = 48;
private final LinkedList<ContextTrack> queue = new LinkedList<>();
private final List<ContextTrack> tracks = new ArrayList<>();
private final FisherYatesShuffle<ContextTrack> shuffle = new FisherYatesShuffle<>(session.random());
Expand Down Expand Up @@ -917,14 +919,14 @@ private void updatePrevNextTracks() {
int index = getCurrentTrackIndex();

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

state.clearNextTracks();
for (ContextTrack track : queue)
state.addNextTracks(ProtoUtils.convertToProvidedTrack(track));

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

Expand Down

0 comments on commit c3a7a11

Please sign in to comment.