1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-06-26 07:02:55 +00:00

Player/handleIntent: always early return on ENQUEUE an ENQUEUE_NEXT

We can do this, because:

1. if `playQueue` is not null, we return early
2. if `playQueue` is null and we need to enqueue:
  - the only “proper” case that could be triggered is
    the `RESUME_PLAYBACK` case, which is never `true` for the queuing
    intents, see the comment in `NavigationHelper.enqueueOnPlayer`
  - the generic `else` case is degenerate, because it would crash on
  `playQueue` being `null`.

This makes some sense, because there is no way to trigger the
enqueueing logic via the UI currently if there is no video playing
yet, in which case `playQueue` is not `null`.

So we need to transform this whole if desaster into a big switch.
This commit is contained in:
Profpatsch 2025-05-04 21:37:14 +02:00
parent 295acc41e1
commit e15c10c15e

View File

@ -368,15 +368,20 @@ public final class Player implements PlaybackListener, Listener {
}
// Resolve enqueue intents
if (intent.getBooleanExtra(ENQUEUE, false) && playQueue != null) {
playQueue.append(newQueue.getStreams());
if (intent.getBooleanExtra(ENQUEUE, false)) {
if (playQueue != null) {
playQueue.append(newQueue.getStreams());
}
return;
}
// Resolve enqueue next intents
} else if (intent.getBooleanExtra(ENQUEUE_NEXT, false) && playQueue != null) {
final int currentIndex = playQueue.getIndex();
playQueue.append(newQueue.getStreams());
playQueue.move(playQueue.size() - 1, currentIndex + 1);
if (intent.getBooleanExtra(ENQUEUE_NEXT, false)) {
if (playQueue != null) {
final int currentIndex = playQueue.getIndex();
playQueue.append(newQueue.getStreams());
playQueue.move(playQueue.size() - 1, currentIndex + 1);
}
return;
}