From bf02a569eee6a08102364783bbb7fa0282ff6a97 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Thu, 9 Dec 2021 21:55:56 +0100 Subject: [PATCH] Fix a NullPointerException when the current metadata is null Reload the play queue manager and set the recovery in this case, like on the current behavior (without this PR). --- .../main/java/org/schabi/newpipe/player/Player.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 791f8efc7..68601a919 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -4177,9 +4177,15 @@ public final class Player implements final int videoRenderIndex = getVideoRendererIndex(); - // We can safely assume that currentMetadata is not null (otherwise this method isn't - // called) so we can use the requireNonNull method of the Objects class. - final StreamInfo info = Objects.requireNonNull(currentMetadata).getMetadata(); + // The current metadata may be null sometimes so we will be not able to execute the + // block above. Reload the play queue manager in this case. + if (currentMetadata == null) { + reloadPlayQueueManager(); + setRecovery(); + return; + } + + final StreamInfo info = currentMetadata.getMetadata(); /* For video streams: we don't want to stream in background the video stream so if the video stream played is not a video-only stream and if there is an audio stream available,