Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #8139

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.PopupMenu;
import androidx.collection.ArraySet;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.GestureDetectorCompat;
Expand Down Expand Up @@ -4217,21 +4218,21 @@ private void useVideoSource(final boolean videoEnabled) {
// in livestreams) so we will be not able to execute the block below.
// Reload the play queue manager in this case, which is the behavior when we don't know the
// index of the video renderer or playQueueManagerReloadingNeeded returns true.
if (!getCurrentStreamInfo().isPresent()) {
final Optional<StreamInfo> optCurrentStreamInfo = getCurrentStreamInfo();
if (!optCurrentStreamInfo.isPresent()) {
reloadPlayQueueManager();
setRecovery();
return;
}

final int videoRenderIndex = getVideoRendererIndex();
final StreamInfo info = getCurrentStreamInfo().get();
final StreamInfo info = optCurrentStreamInfo.get();

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

if (playQueueManagerReloadingNeeded(sourceType, info, videoRenderIndex)) {
if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) {
reloadPlayQueueManager();
} else {
final StreamType streamType = info.getStreamType();
Expand All @@ -4242,19 +4243,22 @@ private void useVideoSource(final boolean videoEnabled) {
return;
}

final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
trackSelector.getCurrentMappedTrackInfo()).getTrackGroups(videoRenderIndex);
final DefaultTrackSelector.ParametersBuilder parametersBuilder =
trackSelector.buildUponParameters();

if (videoEnabled) {
// Clearing the null selection override enable again the video stream (and its
// fetching).
trackSelector.setParameters(trackSelector.buildUponParameters()
.clearSelectionOverride(videoRenderIndex, videoTrackGroupArray));
// Enable again the video track and the subtitles, if there is one selected
parametersBuilder.setDisabledTrackTypes(Collections.emptySet());
} else {
// Using setRendererDisabled still fetch the video stream in background, contrary
// to setSelectionOverride with a null override.
trackSelector.setParameters(trackSelector.buildUponParameters()
.setSelectionOverride(videoRenderIndex, videoTrackGroupArray, null));
// Disable the video track and the ability to select subtitles
// Use an ArraySet because we can't use Set.of() on all supported APIs by the app
final ArraySet<Integer> disabledTracks = new ArraySet<>();
disabledTracks.add(C.TRACK_TYPE_TEXT);
disabledTracks.add(C.TRACK_TYPE_VIDEO);
parametersBuilder.setDisabledTrackTypes(disabledTracks);
}

trackSelector.setParameters(parametersBuilder);
}

setRecovery();
Expand Down