From 2cf77647146f8f839032c0fb9862c8da54aac77c Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Wed, 15 Nov 2023 19:22:49 +0100 Subject: [PATCH] Fix crash when building the play queue audio track menu if the player is null As the player can be null in some cases, we have to make sure that the player is not null, by using Optionals on the player itself instead of its methods returning Optionals. If the player is null, the play queue audio track menu will now be hidden. --- .../java/org/schabi/newpipe/player/PlayQueueActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java index defc8ba21..c012f6008 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java @@ -619,11 +619,13 @@ public final class PlayQueueActivity extends AppCompatActivity final MenuItem audioTrackSelector = menu.findItem(R.id.action_audio_track); final List availableStreams = - Optional.ofNullable(player.getCurrentMetadata()) + Optional.ofNullable(player) + .map(Player::getCurrentMetadata) .flatMap(MediaItemTag::getMaybeAudioTrack) .map(MediaItemTag.AudioTrack::getAudioStreams) .orElse(null); - final Optional selectedAudioStream = player.getSelectedAudioStream(); + final Optional selectedAudioStream = Optional.ofNullable(player) + .flatMap(Player::getSelectedAudioStream); if (availableStreams == null || availableStreams.size() < 2 || selectedAudioStream.isEmpty()) {