Skip to content

Commit 1e8e103

Browse files
committed
Do not rewrite first cached chunk
1 parent e74e43c commit 1e8e103

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

core/src/main/java/xyz/gianlu/librespot/player/feeders/cdn/CdnManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ private Streamer(@NotNull StreamId streamId, @NotNull SuperAudioFormat format, @
207207
this.haltListener = haltListener;
208208
this.cacheHandler = cache != null ? cache.getHandler(streamId) : null;
209209

210+
boolean fromCache;
210211
byte[] firstChunk;
211212
byte[] sizeHeader;
212213
if (cacheHandler == null || (sizeHeader = cacheHandler.getHeader(AudioFileFetch.HEADER_SIZE)) == null) {
@@ -220,6 +221,7 @@ private Streamer(@NotNull StreamId streamId, @NotNull SuperAudioFormat format, @
220221
chunks = (int) Math.ceil((float) size / (float) CHUNK_SIZE);
221222

222223
firstChunk = resp.buffer;
224+
fromCache = false;
223225

224226
if (cacheHandler != null)
225227
cacheHandler.setHeader(AudioFileFetch.HEADER_SIZE, ByteBuffer.allocate(4).putInt(size / 4).array());
@@ -228,6 +230,7 @@ private Streamer(@NotNull StreamId streamId, @NotNull SuperAudioFormat format, @
228230
chunks = (size + CHUNK_SIZE - 1) / CHUNK_SIZE;
229231

230232
firstChunk = cacheHandler.readChunk(0);
233+
fromCache = true;
231234
}
232235

233236
available = new boolean[chunks];
@@ -237,7 +240,7 @@ private Streamer(@NotNull StreamId streamId, @NotNull SuperAudioFormat format, @
237240
buffer[chunks - 1] = new byte[size % CHUNK_SIZE];
238241

239242
this.internalStream = new InternalStream(session.conf());
240-
writeChunk(firstChunk, 0, false);
243+
writeChunk(firstChunk, 0, fromCache);
241244
}
242245

243246
@Override

0 commit comments

Comments
 (0)