From 7d6bf4b0cac4fced6463bfc84c40f48ef57cb00d Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:13:31 +0200 Subject: [PATCH] Improve dialog of streams for external players and fix use of the wrong codec in the list of available streams in it after a codec change in Video and Audio settings The VideoDetailFragment will now get video streams dynamically instead of storing them as a field, so the good codec can be chosen by ListHelper. To select a stream to play, user has now to select the quality in the list of available qualities and then press the new OK button in the alert dialog. --- .../fragments/detail/VideoDetailFragment.java | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index f5bd1f363..bb09681f5 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -188,7 +188,6 @@ public final class VideoDetailFragment @Nullable private Disposable positionSubscriber = null; - private List videoStreamsForExternalPlayers; private BottomSheetBehavior bottomSheetBehavior; private BroadcastReceiver broadcastReceiver; @@ -1615,13 +1614,6 @@ public final class VideoDetailFragment binding.detailToggleSecondaryControlsView.setVisibility(View.VISIBLE); binding.detailSecondaryControlPanel.setVisibility(View.GONE); - final List videoStreams = removeNonUrlAndTorrentStreams( - new ArrayList<>(currentInfo.getVideoStreams())); - final List videoOnlyStreams = removeNonUrlAndTorrentStreams( - new ArrayList<>(currentInfo.getVideoOnlyStreams())); - videoStreamsForExternalPlayers = ListHelper.getSortedStreamVideosList(activity, - videoStreams, videoOnlyStreams, false, false); - updateProgressInfo(info); initThumbnailViews(info); showMetaInfoInTextView(info.getMetaInfo(), binding.detailMetaInfoTextView, @@ -2155,13 +2147,21 @@ public final class VideoDetailFragment return; } + final List videoStreams = removeNonUrlAndTorrentStreams( + new ArrayList<>(currentInfo.getVideoStreams())); + final List videoOnlyStreams = removeNonUrlAndTorrentStreams( + new ArrayList<>(currentInfo.getVideoOnlyStreams())); + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.select_quality_external_players); - builder.setNegativeButton(android.R.string.cancel, null); builder.setNeutralButton(R.string.open_in_browser, (dialog, i) -> ShareUtils.openUrlInBrowser(requireActivity(), url)); + final List videoStreamsForExternalPlayers = + ListHelper.getSortedStreamVideosList(activity, videoStreams, videoOnlyStreams, + false, false); if (videoStreamsForExternalPlayers.isEmpty()) { builder.setMessage(R.string.no_video_streams_available_for_external_players); + builder.setPositiveButton(R.string.ok, null); } else { final int selectedVideoStreamIndexForExternalPlayers = ListHelper.getDefaultResolutionIndex(activity, videoStreamsForExternalPlayers); @@ -2173,11 +2173,19 @@ public final class VideoDetailFragment } builder.setSingleChoiceItems(resolutions, selectedVideoStreamIndexForExternalPlayers, - (dialog, i) -> { - dialog.dismiss(); - startOnExternalPlayer(activity, currentInfo, - videoStreamsForExternalPlayers.get(i)); - }); + null); + builder.setNegativeButton(R.string.cancel, null); + builder.setPositiveButton(R.string.ok, (dialog, i) -> { + final int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); + // We don't have to manage the index validity because if there is no stream + // available for external players, this code will be not executed and if there is + // no stream which matches the default resolution, 0 is returned by + // ListHelper.getDefaultResolutionIndex. + // The index cannot be outside the bounds of the list as its always between 0 and + // the list size - 1, . + startOnExternalPlayer(activity, currentInfo, + videoStreamsForExternalPlayers.get(index)); + }); } builder.show(); }