diff --git a/api/src/main/java/xyz/gianlu/librespot/api/handlers/EventsHandler.java b/api/src/main/java/xyz/gianlu/librespot/api/handlers/EventsHandler.java index 38b6078a..3f88b3ac 100644 --- a/api/src/main/java/xyz/gianlu/librespot/api/handlers/EventsHandler.java +++ b/api/src/main/java/xyz/gianlu/librespot/api/handlers/EventsHandler.java @@ -91,10 +91,11 @@ public void onPlaybackResumed(@NotNull Player player, long trackTime) { } @Override - public void onPlaybackFailed(@NotNull Player player, Exception e) { + public void onPlaybackFailed(@NotNull Player player, @NotNull Exception e) { JsonObject obj = new JsonObject(); obj.addProperty("event", "playbackFailed"); - obj.addProperty("exception", e.getMessage()); + obj.addProperty("exception", e.getClass().getCanonicalName()); + obj.addProperty("message", e.getMessage()); dispatch(obj); } diff --git a/lib/src/main/java/xyz/gianlu/librespot/core/ApResolver.java b/lib/src/main/java/xyz/gianlu/librespot/core/ApResolver.java index a2b7dd65..133d8922 100644 --- a/lib/src/main/java/xyz/gianlu/librespot/core/ApResolver.java +++ b/lib/src/main/java/xyz/gianlu/librespot/core/ApResolver.java @@ -85,20 +85,18 @@ private void request(@NotNull String... types) throws IOException { try (Response response = client.newCall(request).execute()) { ResponseBody body = response.body(); if (body == null) throw new IOException("No body"); - try (Reader reader = body.charStream()) { - JsonObject obj = JsonParser.parseReader(reader).getAsJsonObject(); - HashMap> map = new HashMap<>(); - for (String type : types) - map.put(type, getUrls(obj, type)); - - synchronized (pool) { - pool.putAll(map); - poolReady = true; - pool.notifyAll(); - } + JsonObject obj = JsonParser.parseReader(body.charStream()).getAsJsonObject(); + HashMap> map = new HashMap<>(); + for (String type : types) + map.put(type, getUrls(obj, type)); - LOGGER.info("Loaded aps into pool: " + pool); + synchronized (pool) { + pool.putAll(map); + poolReady = true; + pool.notifyAll(); } + + LOGGER.info("Loaded aps into pool: " + pool); } } diff --git a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java index 664167b7..534b4686 100644 --- a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java +++ b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java @@ -718,13 +718,13 @@ private void reconnect() { } try { - apResolver.refreshPool(); - if (conn != null) { - conn.socket.close(); receiver.stop(); + conn.socket.close(); } + apResolver.refreshPool(); + conn = ConnectionHolder.create(apResolver.getRandomAccesspoint(), inner.conf); connect(); authenticatePartial(Authentication.LoginCredentials.newBuilder() diff --git a/player/src/main/java/xyz/gianlu/librespot/player/Player.java b/player/src/main/java/xyz/gianlu/librespot/player/Player.java index 824ba57f..83420e21 100644 --- a/player/src/main/java/xyz/gianlu/librespot/player/Player.java +++ b/player/src/main/java/xyz/gianlu/librespot/player/Player.java @@ -872,7 +872,7 @@ public interface EventsListener { void onPlaybackResumed(@NotNull Player player, long trackTime); - void onPlaybackFailed(@NotNull Player player, Exception e); + void onPlaybackFailed(@NotNull Player player, @NotNull Exception e); void onTrackSeeked(@NotNull Player player, long trackTime); @@ -1005,7 +1005,7 @@ public void onPlaybackResumed(@NotNull Player player, long trackTime) { } @Override - public void onPlaybackFailed(@NotNull Player player, Exception e) { + public void onPlaybackFailed(@NotNull Player player, @NotNull Exception e) { } @Override @@ -1082,7 +1082,7 @@ void playbackResumed() { executorService.execute(() -> l.onPlaybackResumed(Player.this, trackTime)); } - void playbackFailed(Exception ex) { + void playbackFailed(@NotNull Exception ex) { for (EventsListener l : new ArrayList<>(listeners)) executorService.execute(() -> l.onPlaybackFailed(Player.this, ex)); } diff --git a/player/src/main/java/xyz/gianlu/librespot/player/ShellEvents.java b/player/src/main/java/xyz/gianlu/librespot/player/ShellEvents.java index 57529363..11ba1613 100644 --- a/player/src/main/java/xyz/gianlu/librespot/player/ShellEvents.java +++ b/player/src/main/java/xyz/gianlu/librespot/player/ShellEvents.java @@ -89,7 +89,7 @@ public void onPlaybackResumed(@NotNull Player player, long trackTime) { } @Override - public void onPlaybackFailed(@NotNull Player player, Exception e) { + public void onPlaybackFailed(@NotNull Player player, @NotNull Exception e) { exec(conf.onPlaybackFailed, "EXCEPTION=" + e.getClass().getCanonicalName(), "MESSAGE=" + e.getMessage()); }