Skip to content

Commit 3b6bcad

Browse files
committed
Revert "Avoid NPE with metrics + catch 400 when loading autoplay (#284)"
This reverts commit 1bcb832
1 parent 6d34aba commit 3b6bcad

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

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

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

349349
public static class MercuryException extends Exception {
350-
public final int code;
351-
352350
private MercuryException(@NotNull Response response) {
353351
super(String.format("status: %d", response.statusCode));
354-
this.code = response.statusCode;
355352
}
356353
}
357354

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);
5857
private StateWrapper state;
5958
private PlayerSession playerSession;
6059
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.clear();
210+
metrics = null;
211211
} else if (playerSession != null) {
212212
endMetrics(playerSession.currentPlaybackId(), reason, playerSession.currentMetrics(), state.getPosition());
213213
}
@@ -501,6 +501,14 @@ 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+
}
504512

505513
String contextDesc = state.getContextMetadata("context_description");
506514

@@ -532,16 +540,8 @@ private void loadAutoplay() {
532540
state.updated();
533541
}
534542
} catch (IOException | MercuryClient.MercuryException ex) {
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-
}
543+
LOGGER.fatal("Failed loading autoplay station!", ex);
544+
panicState(null);
545545
} catch (AbsSpotifyContext.UnsupportedContextException ex) {
546546
LOGGER.fatal("Cannot play local tracks!", ex);
547547
panicState(null);

0 commit comments

Comments
 (0)