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.
This commit is contained in:
AudricV 2023-11-15 19:22:49 +01:00
parent 6d694518fe
commit 2cf7764714
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
1 changed files with 4 additions and 2 deletions

View File

@ -619,11 +619,13 @@ public final class PlayQueueActivity extends AppCompatActivity
final MenuItem audioTrackSelector = menu.findItem(R.id.action_audio_track);
final List<AudioStream> availableStreams =
Optional.ofNullable(player.getCurrentMetadata())
Optional.ofNullable(player)
.map(Player::getCurrentMetadata)
.flatMap(MediaItemTag::getMaybeAudioTrack)
.map(MediaItemTag.AudioTrack::getAudioStreams)
.orElse(null);
final Optional<AudioStream> selectedAudioStream = player.getSelectedAudioStream();
final Optional<AudioStream> selectedAudioStream = Optional.ofNullable(player)
.flatMap(Player::getSelectedAudioStream);
if (availableStreams == null || availableStreams.size() < 2
|| selectedAudioStream.isEmpty()) {