Skip to content

Commit c34d20e

Browse files
committed
Close entries when seeking only if active
1 parent 997d94d commit c34d20e

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/player/playback/PlayerQueueEntry.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void seek(int pos) {
181181
* @throws IllegalStateException If the output is already set. Will also clear {@param output}.
182182
*/
183183
void setOutput(@NotNull MixingLine.MixingOutput output) {
184-
if (closed || this.output != null) {
184+
if (closed || hasOutput()) {
185185
output.clear();
186186
throw new IllegalStateException("Cannot set output for " + this);
187187
}
@@ -211,6 +211,13 @@ private void clearOutput() {
211211
}
212212
}
213213

214+
/**
215+
* @return Whether the entry is associated with an output.
216+
*/
217+
public boolean hasOutput() {
218+
return output != null;
219+
}
220+
214221
/**
215222
* Instructs to notify when this time instant is reached.
216223
*
@@ -310,7 +317,7 @@ public void run() {
310317
}
311318
}
312319

313-
output.toggle(false);
320+
if (output != null) output.toggle(false);
314321
listener.playbackEnded(this);
315322
LOGGER.trace("{} terminated.", this);
316323
}
@@ -330,7 +337,7 @@ private void checkInstants(int time) {
330337
* @return Whether it has been closed
331338
*/
332339
boolean closeIfUseless() {
333-
if (output == null) {
340+
if (!hasOutput()) {
334341
close();
335342
return true;
336343
}

core/src/main/java/xyz/gianlu/librespot/player/playback/PlayerSession.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ public String play(@NotNull PlayableId playable, int pos, @NotNull Reason reason
286286
public void seekCurrent(int pos) {
287287
if (queue.head() == null) return;
288288

289-
if (queue.prev() != null) queue.remove(queue.prev());
290-
if (queue.next() != null) queue.remove(queue.next());
289+
PlayerQueueEntry entry;
290+
if ((entry = queue.prev()) != null && entry.hasOutput()) queue.remove(entry);
291+
if ((entry = queue.next()) != null && entry.hasOutput()) queue.remove(entry);
291292

292293
queue.head().seek(pos);
293294
sink.flush();

0 commit comments

Comments
 (0)