Skip to content

Commit

Permalink
Improve dialog of streams for external players and fix use of the wro…
Browse files Browse the repository at this point in the history
…ng 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.
  • Loading branch information
AudricV committed May 2, 2022
1 parent 9b2eab7 commit ce2cdaf
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public final class VideoDetailFragment
@Nullable
private Disposable positionSubscriber = null;

private List<VideoStream> videoStreamsForExternalPlayers;
private BottomSheetBehavior<FrameLayout> bottomSheetBehavior;
private BroadcastReceiver broadcastReceiver;

Expand Down Expand Up @@ -1616,13 +1615,6 @@ public void handleResult(@NonNull final StreamInfo info) {
binding.detailToggleSecondaryControlsView.setVisibility(View.VISIBLE);
binding.detailSecondaryControlPanel.setVisibility(View.GONE);

final List<VideoStream> videoStreams = removeNonUrlAndTorrentStreams(
new ArrayList<>(currentInfo.getVideoStreams()));
final List<VideoStream> videoOnlyStreams = removeNonUrlAndTorrentStreams(
new ArrayList<>(currentInfo.getVideoOnlyStreams()));
videoStreamsForExternalPlayers = ListHelper.getSortedStreamVideosList(activity,
videoStreams, videoOnlyStreams, false, false);

updateProgressInfo(info);
initThumbnailViews(info);
showMetaInfoInTextView(info.getMetaInfo(), binding.detailMetaInfoTextView,
Expand Down Expand Up @@ -2157,13 +2149,21 @@ private void showExternalPlaybackDialog() {
return;
}

final List<VideoStream> videoStreams = removeNonUrlAndTorrentStreams(
new ArrayList<>(currentInfo.getVideoStreams()));
final List<VideoStream> 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<VideoStream> 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);
Expand All @@ -2175,11 +2175,19 @@ private void showExternalPlaybackDialog() {
}

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();
}
Expand Down

0 comments on commit ce2cdaf

Please sign in to comment.