Skip to content

Commit e9e39b5

Browse files
committed
Set context description for autoplay stations
1 parent e764c35 commit e9e39b5

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,18 +533,22 @@ private void loadAutoplay() {
533533
return;
534534
}
535535

536+
String contextDesc = state.getContextMetadata("context_description");
537+
536538
try {
537539
MercuryClient.Response resp = session.mercury().sendSync(MercuryRequests.autoplayQuery(context));
538540
if (resp.statusCode == 200) {
539541
String newContext = resp.payload.readIntoString(0);
540542
state.loadContext(newContext);
543+
state.setContextMetadata("context_description", contextDesc);
541544

542545
loadTrack(true, PushToMixerReason.None);
543546

544547
LOGGER.debug(String.format("Loading context for autoplay, uri: %s", newContext));
545548
} else if (resp.statusCode == 204) {
546549
MercuryRequests.StationsWrapper station = session.mercury().sendSync(MercuryRequests.getStationFor(context));
547550
state.loadContextWithTracks(station.uri(), station.tracks());
551+
state.setContextMetadata("context_description", contextDesc);
548552

549553
loadTrack(true, PushToMixerReason.None);
550554

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ synchronized int getVolume() {
289289
return device.getVolume();
290290
}
291291

292+
void setVolume(int val) {
293+
device.setVolume(val);
294+
}
295+
292296
synchronized void enrichWithMetadata(@NotNull Metadata.Track track) {
293297
if (state.getTrack() == null) throw new IllegalStateException();
294298
if (!state.getTrack().getUri().equals(PlayableId.from(track).toSpotifyUri())) {
@@ -664,8 +668,14 @@ private synchronized void performCollectionUpdate(@NotNull List<String> uris, bo
664668
tracksKeeper.updateMetadataFor(uri, "collection.in_collection", String.valueOf(inCollection));
665669
}
666670

667-
void setVolume(int val) {
668-
device.setVolume(val);
671+
@Nullable
672+
public String getContextMetadata(@NotNull String key) {
673+
return state.getContextMetadataOrDefault(key, null);
674+
}
675+
676+
public void setContextMetadata(@NotNull String key, @Nullable String value) {
677+
if (value == null) state.removeContextMetadata(key);
678+
else state.putContextMetadata(key, value);
669679
}
670680

671681
public enum PreviousPlayable {

0 commit comments

Comments
 (0)