Skip to content

Commit 7d6bf4b

Browse files
committed
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.
1 parent 210834f commit 7d6bf4b

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ public final class VideoDetailFragment
188188
@Nullable
189189
private Disposable positionSubscriber = null;
190190

191-
private List<VideoStream> videoStreamsForExternalPlayers;
192191
private BottomSheetBehavior<FrameLayout> bottomSheetBehavior;
193192
private BroadcastReceiver broadcastReceiver;
194193

@@ -1615,13 +1614,6 @@ public void handleResult(@NonNull final StreamInfo info) {
16151614
binding.detailToggleSecondaryControlsView.setVisibility(View.VISIBLE);
16161615
binding.detailSecondaryControlPanel.setVisibility(View.GONE);
16171616

1618-
final List<VideoStream> videoStreams = removeNonUrlAndTorrentStreams(
1619-
new ArrayList<>(currentInfo.getVideoStreams()));
1620-
final List<VideoStream> videoOnlyStreams = removeNonUrlAndTorrentStreams(
1621-
new ArrayList<>(currentInfo.getVideoOnlyStreams()));
1622-
videoStreamsForExternalPlayers = ListHelper.getSortedStreamVideosList(activity,
1623-
videoStreams, videoOnlyStreams, false, false);
1624-
16251617
updateProgressInfo(info);
16261618
initThumbnailViews(info);
16271619
showMetaInfoInTextView(info.getMetaInfo(), binding.detailMetaInfoTextView,
@@ -2155,13 +2147,21 @@ private void showExternalPlaybackDialog() {
21552147
return;
21562148
}
21572149

2150+
final List<VideoStream> videoStreams = removeNonUrlAndTorrentStreams(
2151+
new ArrayList<>(currentInfo.getVideoStreams()));
2152+
final List<VideoStream> videoOnlyStreams = removeNonUrlAndTorrentStreams(
2153+
new ArrayList<>(currentInfo.getVideoOnlyStreams()));
2154+
21582155
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
21592156
builder.setTitle(R.string.select_quality_external_players);
2160-
builder.setNegativeButton(android.R.string.cancel, null);
21612157
builder.setNeutralButton(R.string.open_in_browser, (dialog, i) ->
21622158
ShareUtils.openUrlInBrowser(requireActivity(), url));
2159+
final List<VideoStream> videoStreamsForExternalPlayers =
2160+
ListHelper.getSortedStreamVideosList(activity, videoStreams, videoOnlyStreams,
2161+
false, false);
21632162
if (videoStreamsForExternalPlayers.isEmpty()) {
21642163
builder.setMessage(R.string.no_video_streams_available_for_external_players);
2164+
builder.setPositiveButton(R.string.ok, null);
21652165
} else {
21662166
final int selectedVideoStreamIndexForExternalPlayers =
21672167
ListHelper.getDefaultResolutionIndex(activity, videoStreamsForExternalPlayers);
@@ -2173,11 +2173,19 @@ private void showExternalPlaybackDialog() {
21732173
}
21742174

21752175
builder.setSingleChoiceItems(resolutions, selectedVideoStreamIndexForExternalPlayers,
2176-
(dialog, i) -> {
2177-
dialog.dismiss();
2178-
startOnExternalPlayer(activity, currentInfo,
2179-
videoStreamsForExternalPlayers.get(i));
2180-
});
2176+
null);
2177+
builder.setNegativeButton(R.string.cancel, null);
2178+
builder.setPositiveButton(R.string.ok, (dialog, i) -> {
2179+
final int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
2180+
// We don't have to manage the index validity because if there is no stream
2181+
// available for external players, this code will be not executed and if there is
2182+
// no stream which matches the default resolution, 0 is returned by
2183+
// ListHelper.getDefaultResolutionIndex.
2184+
// The index cannot be outside the bounds of the list as its always between 0 and
2185+
// the list size - 1, .
2186+
startOnExternalPlayer(activity, currentInfo,
2187+
videoStreamsForExternalPlayers.get(index));
2188+
});
21812189
}
21822190
builder.show();
21832191
}

0 commit comments

Comments
 (0)