Skip to content

Commit c3473bd

Browse files
authored
Merge pull request #464 from Iscle/reconnection-fix
Refresh the AP pool after stopping the receiver
2 parents 58defc7 + 09569b7 commit c3473bd

5 files changed

Lines changed: 20 additions & 21 deletions

File tree

api/src/main/java/xyz/gianlu/librespot/api/handlers/EventsHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ public void onPlaybackResumed(@NotNull Player player, long trackTime) {
9191
}
9292

9393
@Override
94-
public void onPlaybackFailed(@NotNull Player player, Exception e) {
94+
public void onPlaybackFailed(@NotNull Player player, @NotNull Exception e) {
9595
JsonObject obj = new JsonObject();
9696
obj.addProperty("event", "playbackFailed");
97-
obj.addProperty("exception", e.getMessage());
97+
obj.addProperty("exception", e.getClass().getCanonicalName());
98+
obj.addProperty("message", e.getMessage());
9899
dispatch(obj);
99100
}
100101

lib/src/main/java/xyz/gianlu/librespot/core/ApResolver.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,18 @@ private void request(@NotNull String... types) throws IOException {
8585
try (Response response = client.newCall(request).execute()) {
8686
ResponseBody body = response.body();
8787
if (body == null) throw new IOException("No body");
88-
try (Reader reader = body.charStream()) {
89-
JsonObject obj = JsonParser.parseReader(reader).getAsJsonObject();
90-
HashMap<String, List<String>> map = new HashMap<>();
91-
for (String type : types)
92-
map.put(type, getUrls(obj, type));
93-
94-
synchronized (pool) {
95-
pool.putAll(map);
96-
poolReady = true;
97-
pool.notifyAll();
98-
}
88+
JsonObject obj = JsonParser.parseReader(body.charStream()).getAsJsonObject();
89+
HashMap<String, List<String>> map = new HashMap<>();
90+
for (String type : types)
91+
map.put(type, getUrls(obj, type));
9992

100-
LOGGER.info("Loaded aps into pool: " + pool);
93+
synchronized (pool) {
94+
pool.putAll(map);
95+
poolReady = true;
96+
pool.notifyAll();
10197
}
98+
99+
LOGGER.info("Loaded aps into pool: " + pool);
102100
}
103101
}
104102

lib/src/main/java/xyz/gianlu/librespot/core/Session.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,13 @@ private void reconnect() {
718718
}
719719

720720
try {
721-
apResolver.refreshPool();
722-
723721
if (conn != null) {
724-
conn.socket.close();
725722
receiver.stop();
723+
conn.socket.close();
726724
}
727725

726+
apResolver.refreshPool();
727+
728728
conn = ConnectionHolder.create(apResolver.getRandomAccesspoint(), inner.conf);
729729
connect();
730730
authenticatePartial(Authentication.LoginCredentials.newBuilder()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ public interface EventsListener {
872872

873873
void onPlaybackResumed(@NotNull Player player, long trackTime);
874874

875-
void onPlaybackFailed(@NotNull Player player, Exception e);
875+
void onPlaybackFailed(@NotNull Player player, @NotNull Exception e);
876876

877877
void onTrackSeeked(@NotNull Player player, long trackTime);
878878

@@ -1005,7 +1005,7 @@ public void onPlaybackResumed(@NotNull Player player, long trackTime) {
10051005
}
10061006

10071007
@Override
1008-
public void onPlaybackFailed(@NotNull Player player, Exception e) {
1008+
public void onPlaybackFailed(@NotNull Player player, @NotNull Exception e) {
10091009
}
10101010

10111011
@Override
@@ -1082,7 +1082,7 @@ void playbackResumed() {
10821082
executorService.execute(() -> l.onPlaybackResumed(Player.this, trackTime));
10831083
}
10841084

1085-
void playbackFailed(Exception ex) {
1085+
void playbackFailed(@NotNull Exception ex) {
10861086
for (EventsListener l : new ArrayList<>(listeners))
10871087
executorService.execute(() -> l.onPlaybackFailed(Player.this, ex));
10881088
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void onPlaybackResumed(@NotNull Player player, long trackTime) {
8989
}
9090

9191
@Override
92-
public void onPlaybackFailed(@NotNull Player player, Exception e) {
92+
public void onPlaybackFailed(@NotNull Player player, @NotNull Exception e) {
9393
exec(conf.onPlaybackFailed, "EXCEPTION=" + e.getClass().getCanonicalName(), "MESSAGE=" + e.getMessage());
9494
}
9595

0 commit comments

Comments
 (0)