Skip to content

Commit f774052

Browse files
committed
Merge branch 'master' into dev
2 parents 5c1a142 + 1bcb832 commit f774052

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
3434
- Fixed starting playback from API (#254)
3535

3636

37+
## [1.5.2] - 17-11-2020
38+
### Added
39+
- Added `Player#waitReady()` method (d3149d3843e066986524e14369c5871c22629810)
40+
- Added pass through endpoints for official Spotify API (#255)
41+
- Store and check hash of first chunk of cache data (9ab9f43a91ebbce0e9a3a3c6f3c55a714c756525)
42+
43+
### Fixed
44+
- Fixed `UnsupportedOperationException` when starting playback (#251)
45+
- Close cache files correctly (e953129ed5f0dc4e9931660bd216267557d6010a, #253)
46+
- Fixed starting playback from API (#254)
47+
48+
3749
## [1.5.1] - 31-07-2020
3850
### Fixed
3951
- Fixed issue with Zeroconf (#246)

lib/src/main/java/xyz/gianlu/librespot/common/ProtoUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,19 @@ public static void enrichTrack(@NotNull Player.ProvidedTrack.Builder subject, @N
292292
}
293293

294294
@Nullable
295-
@Contract("null -> null")
296-
public static Player.ProvidedTrack toProvidedTrack(@Nullable ContextTrack track) {
295+
@Contract("null, _ -> null")
296+
public static Player.ProvidedTrack toProvidedTrack(@Nullable ContextTrack track, String contextUri) {
297297
if (track == null) return null;
298298

299299
Player.ProvidedTrack.Builder builder = Player.ProvidedTrack.newBuilder();
300300
builder.setProvider("context");
301-
if (track.hasUri() && !track.getUri().isEmpty()) builder.setUri(track.getUri());
302301
if (track.hasUid()) builder.setUid(track.getUid());
302+
if (track.hasUri() && !track.getUri().isEmpty()) {
303+
builder.setUri(track.getUri());
304+
} else if (track.hasGid()) {
305+
String uriPrefix = PlayableId.inferUriPrefix(contextUri);
306+
builder.setUri(uriPrefix + new String(PlayableId.BASE62.encode(track.getGid().toByteArray(), 22)));
307+
}
303308

304309
try {
305310
builder.setAlbumUri(track.getMetadataOrThrow("album_uri"));

lib/src/main/java/xyz/gianlu/librespot/mercury/MercuryClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,11 @@ void dispatch(@NotNull Response resp) {
347347
}
348348

349349
public static class MercuryException extends Exception {
350+
public final int code;
351+
350352
private MercuryException(@NotNull Response response) {
351353
super(String.format("status: %d", response.statusCode));
354+
this.code = response.statusCode;
352355
}
353356
}
354357

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class Player implements Closeable, DeviceStateHandler.Listener, PlayerSes
5454
private final PlayerConfiguration conf;
5555
private final EventsDispatcher events;
5656
private final AudioSink sink;
57+
private final Map<String, PlaybackMetrics> metrics = new HashMap<>(5);
5758
private StateWrapper state;
5859
private PlayerSession playerSession;
5960
private ScheduledFuture<?> releaseLineFuture = null;
60-
private Map<String, PlaybackMetrics> metrics = new HashMap<>(5);
6161

6262
public Player(@NotNull PlayerConfiguration conf, @NotNull Session session) {
6363
this.conf = conf;
@@ -207,7 +207,7 @@ private void panicState(@Nullable PlaybackMetrics.Reason reason) {
207207
state.updated();
208208

209209
if (reason == null) {
210-
metrics = null;
210+
metrics.clear();
211211
} else if (playerSession != null) {
212212
endMetrics(playerSession.currentPlaybackId(), reason, playerSession.currentMetrics(), state.getPosition());
213213
}
@@ -501,14 +501,6 @@ private void loadAutoplay() {
501501
return;
502502
}
503503

504-
if (context.startsWith("spotify:search:")) {
505-
LOGGER.info("Cannot load autoplay for search context: " + context);
506-
507-
state.setPosition(0);
508-
state.setState(true, false, false);
509-
state.updated();
510-
return;
511-
}
512504

513505
String contextDesc = state.getContextMetadata("context_description");
514506

@@ -540,8 +532,16 @@ private void loadAutoplay() {
540532
state.updated();
541533
}
542534
} catch (IOException | MercuryClient.MercuryException ex) {
543-
LOGGER.fatal("Failed loading autoplay station!", ex);
544-
panicState(null);
535+
if (ex instanceof MercuryClient.MercuryException && ((MercuryClient.MercuryException) ex).code == 400) {
536+
LOGGER.info("Cannot load autoplay for search context: " + context);
537+
538+
state.setPosition(0);
539+
state.setState(true, true, false);
540+
state.updated();
541+
} else {
542+
LOGGER.fatal("Failed loading autoplay station!", ex);
543+
panicState(null);
544+
}
545545
} catch (AbsSpotifyContext.UnsupportedContextException ex) {
546546
LOGGER.fatal("Cannot play local tracks!", ex);
547547
panicState(null);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,14 @@ private void updatePrevNextTracks() {
930930

931931
state.clearPrevTracks();
932932
for (int i = Math.max(0, index - MAX_PREV_TRACKS); i < index; i++)
933-
state.addPrevTracks(ProtoUtils.toProvidedTrack(tracks.get(i)));
933+
state.addPrevTracks(ProtoUtils.toProvidedTrack(tracks.get(i), getContextUri()));
934934

935935
state.clearNextTracks();
936936
for (ContextTrack track : queue)
937-
state.addNextTracks(ProtoUtils.toProvidedTrack(track));
937+
state.addNextTracks(ProtoUtils.toProvidedTrack(track, getContextUri()));
938938

939939
for (int i = index + 1; i < Math.min(tracks.size(), index + 1 + MAX_NEXT_TRACKS); i++)
940-
state.addNextTracks(ProtoUtils.toProvidedTrack(tracks.get(i)));
940+
state.addNextTracks(ProtoUtils.toProvidedTrack(tracks.get(i), getContextUri()));
941941
}
942942

943943
void updateTrackDuration(int duration) {
@@ -976,8 +976,8 @@ private void updateLikeDislike() {
976976
* <b>This will also REMOVE a track from the queue if needed. Calling this twice will break the queue.</b>
977977
*/
978978
private void updateState() {
979-
if (isPlayingQueue) state.setTrack(ProtoUtils.toProvidedTrack(queue.remove()));
980-
else state.setTrack(ProtoUtils.toProvidedTrack(tracks.get(getCurrentTrackIndex())));
979+
if (isPlayingQueue) state.setTrack(ProtoUtils.toProvidedTrack(queue.remove(), getContextUri()));
980+
else state.setTrack(ProtoUtils.toProvidedTrack(tracks.get(getCurrentTrackIndex()), getContextUri()));
981981

982982
updateLikeDislike();
983983

@@ -1116,7 +1116,7 @@ private void enrichCurrentTrack(@NotNull ContextTrack track) {
11161116
ContextTrack.Builder current = tracks.get(index).toBuilder();
11171117
ProtoUtils.enrichTrack(current, track);
11181118
tracks.set(index, current.build());
1119-
state.setTrack(ProtoUtils.toProvidedTrack(current.build()));
1119+
state.setTrack(ProtoUtils.toProvidedTrack(current.build(), getContextUri()));
11201120
}
11211121
}
11221122

0 commit comments

Comments
 (0)