Skip to content

Commit f5415bf

Browse files
committed
Handling stream error better
1 parent 929c694 commit f5415bf

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ public interface AudioFile {
1717
void cacheFailedHeader(@NotNull AudioFile file);
1818

1919
void headerEnd(boolean cached);
20+
21+
void streamError(short code);
2022
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public synchronized void headerEnd(boolean cached) {
6262
}
6363
}
6464

65+
@Override
66+
public void streamError(short code) {
67+
LOGGER.fatal(String.format("Stream error, code: %d", code));
68+
}
69+
6570
@Override
6671
public synchronized void cacheFailedChunk(int index, @NotNull AudioFile file) {
6772
// Never called

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import org.apache.log4j.Logger;
55
import org.jetbrains.annotations.NotNull;
66
import xyz.gianlu.librespot.common.Utils;
7-
import xyz.gianlu.librespot.core.Session;
87
import xyz.gianlu.librespot.common.proto.Metadata;
8+
import xyz.gianlu.librespot.core.Session;
99

1010
import java.io.IOException;
1111
import java.io.InputStream;
@@ -119,6 +119,11 @@ public void headerEnd(boolean cached) {
119119
// Never called
120120
}
121121

122+
@Override
123+
public void streamError(short code) {
124+
LOGGER.fatal(String.format("Stream error, code: %d", code));
125+
}
126+
122127
private class ChunksBuffer {
123128
private final int size;
124129
private final byte[][] buffer;

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ protected void appendToQueue(@NotNull Packet packet) {
7676

7777
channel.addToQueue(payload);
7878
} else if (packet.is(Packet.Type.ChannelError)) {
79-
LOGGER.fatal(String.format("Stream error, payload: %s", Utils.bytesToHex(packet.payload)));
79+
short id = payload.getShort();
80+
Channel channel = channels.get(id);
81+
if (channel == null) {
82+
LOGGER.warn(String.format("Dropping channel error, id: %d, code: %d", id, payload.getShort()));
83+
return;
84+
}
85+
86+
channel.streamError(payload.getShort());
8087
} else {
8188
LOGGER.warn(String.format("Couldn't handle packet, cmd: %s, payload: %s", packet.type(), Utils.bytesToHex(packet.payload)));
8289
}
@@ -147,6 +154,10 @@ private void addToQueue(@NotNull ByteBuffer payload) {
147154
queue.add(payload);
148155
}
149156

157+
void streamError(short code) {
158+
file.streamError(code);
159+
}
160+
150161
private class Handler implements Runnable {
151162

152163
@Override

0 commit comments

Comments
 (0)