Skip to content

Commit 3261855

Browse files
committed
Fix fetch of video streams (when switching between tracks in a play queue) and subtitles when using a seamless transition between background and video players
Make the use of the new method setDisabledTrackTypes in DefaultTrackSelector.ParametersBuilder, which disables selection of tracks type for every TrackGroup instead of the current group, which is the current behavior. This removes the use of the deprecated of setSelectionOverride method. Note that for progressive media, the content is still fetched, but only for initialization purposes (so requests are pretty small, most of times with a few kilobytes size).
1 parent 629b685 commit 3261855

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import androidx.appcompat.view.ContextThemeWrapper;
117117
import androidx.appcompat.widget.AppCompatImageButton;
118118
import androidx.appcompat.widget.PopupMenu;
119+
import androidx.collection.ArraySet;
119120
import androidx.core.content.ContextCompat;
120121
import androidx.core.graphics.Insets;
121122
import androidx.core.view.GestureDetectorCompat;
@@ -4217,21 +4218,21 @@ private void useVideoSource(final boolean videoEnabled) {
42174218
// in livestreams) so we will be not able to execute the block below.
42184219
// Reload the play queue manager in this case, which is the behavior when we don't know the
42194220
// index of the video renderer or playQueueManagerReloadingNeeded returns true.
4220-
if (!getCurrentStreamInfo().isPresent()) {
4221+
final Optional<StreamInfo> optCurrentStreamInfo = getCurrentStreamInfo();
4222+
if (!optCurrentStreamInfo.isPresent()) {
42214223
reloadPlayQueueManager();
42224224
setRecovery();
42234225
return;
42244226
}
42254227

4226-
final int videoRenderIndex = getVideoRendererIndex();
4227-
final StreamInfo info = getCurrentStreamInfo().get();
4228+
final StreamInfo info = optCurrentStreamInfo.get();
42284229

42294230
// In the case we don't know the source type, fallback to the one with video with audio or
42304231
// audio-only source.
42314232
final SourceType sourceType = videoResolver.getStreamSourceType().orElse(
42324233
SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);
42334234

4234-
if (playQueueManagerReloadingNeeded(sourceType, info, videoRenderIndex)) {
4235+
if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) {
42354236
reloadPlayQueueManager();
42364237
} else {
42374238
final StreamType streamType = info.getStreamType();
@@ -4242,19 +4243,22 @@ private void useVideoSource(final boolean videoEnabled) {
42424243
return;
42434244
}
42444245

4245-
final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
4246-
trackSelector.getCurrentMappedTrackInfo()).getTrackGroups(videoRenderIndex);
4246+
final DefaultTrackSelector.ParametersBuilder parametersBuilder =
4247+
trackSelector.buildUponParameters();
4248+
42474249
if (videoEnabled) {
4248-
// Clearing the null selection override enable again the video stream (and its
4249-
// fetching).
4250-
trackSelector.setParameters(trackSelector.buildUponParameters()
4251-
.clearSelectionOverride(videoRenderIndex, videoTrackGroupArray));
4250+
// Enable again the video track and the subtitles, if there is one selected
4251+
parametersBuilder.setDisabledTrackTypes(Collections.emptySet());
42524252
} else {
4253-
// Using setRendererDisabled still fetch the video stream in background, contrary
4254-
// to setSelectionOverride with a null override.
4255-
trackSelector.setParameters(trackSelector.buildUponParameters()
4256-
.setSelectionOverride(videoRenderIndex, videoTrackGroupArray, null));
4253+
// Disable the video track and the ability to select subtitles
4254+
// Use an ArraySet because we can't use Set.of() on all supported APIs by the app
4255+
final ArraySet<Integer> disabledTracks = new ArraySet<>();
4256+
disabledTracks.add(C.TRACK_TYPE_TEXT);
4257+
disabledTracks.add(C.TRACK_TYPE_VIDEO);
4258+
parametersBuilder.setDisabledTrackTypes(disabledTracks);
42574259
}
4260+
4261+
trackSelector.setParameters(parametersBuilder);
42584262
}
42594263

42604264
setRecovery();

0 commit comments

Comments
 (0)