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).
This commit is contained in:
parent
629b685f5a
commit
3261855b8f
|
@ -116,6 +116,7 @@ import androidx.appcompat.content.res.AppCompatResources;
|
||||||
import androidx.appcompat.view.ContextThemeWrapper;
|
import androidx.appcompat.view.ContextThemeWrapper;
|
||||||
import androidx.appcompat.widget.AppCompatImageButton;
|
import androidx.appcompat.widget.AppCompatImageButton;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
import androidx.collection.ArraySet;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.graphics.Insets;
|
import androidx.core.graphics.Insets;
|
||||||
import androidx.core.view.GestureDetectorCompat;
|
import androidx.core.view.GestureDetectorCompat;
|
||||||
|
@ -4217,21 +4218,21 @@ public final class Player implements
|
||||||
// in livestreams) so we will be not able to execute the block below.
|
// 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
|
// 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.
|
// index of the video renderer or playQueueManagerReloadingNeeded returns true.
|
||||||
if (!getCurrentStreamInfo().isPresent()) {
|
final Optional<StreamInfo> optCurrentStreamInfo = getCurrentStreamInfo();
|
||||||
|
if (!optCurrentStreamInfo.isPresent()) {
|
||||||
reloadPlayQueueManager();
|
reloadPlayQueueManager();
|
||||||
setRecovery();
|
setRecovery();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int videoRenderIndex = getVideoRendererIndex();
|
final StreamInfo info = optCurrentStreamInfo.get();
|
||||||
final StreamInfo info = getCurrentStreamInfo().get();
|
|
||||||
|
|
||||||
// In the case we don't know the source type, fallback to the one with video with audio or
|
// In the case we don't know the source type, fallback to the one with video with audio or
|
||||||
// audio-only source.
|
// audio-only source.
|
||||||
final SourceType sourceType = videoResolver.getStreamSourceType().orElse(
|
final SourceType sourceType = videoResolver.getStreamSourceType().orElse(
|
||||||
SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);
|
SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);
|
||||||
|
|
||||||
if (playQueueManagerReloadingNeeded(sourceType, info, videoRenderIndex)) {
|
if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) {
|
||||||
reloadPlayQueueManager();
|
reloadPlayQueueManager();
|
||||||
} else {
|
} else {
|
||||||
final StreamType streamType = info.getStreamType();
|
final StreamType streamType = info.getStreamType();
|
||||||
|
@ -4242,19 +4243,22 @@ public final class Player implements
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
|
final DefaultTrackSelector.ParametersBuilder parametersBuilder =
|
||||||
trackSelector.getCurrentMappedTrackInfo()).getTrackGroups(videoRenderIndex);
|
trackSelector.buildUponParameters();
|
||||||
|
|
||||||
if (videoEnabled) {
|
if (videoEnabled) {
|
||||||
// Clearing the null selection override enable again the video stream (and its
|
// Enable again the video track and the subtitles, if there is one selected
|
||||||
// fetching).
|
parametersBuilder.setDisabledTrackTypes(Collections.emptySet());
|
||||||
trackSelector.setParameters(trackSelector.buildUponParameters()
|
|
||||||
.clearSelectionOverride(videoRenderIndex, videoTrackGroupArray));
|
|
||||||
} else {
|
} else {
|
||||||
// Using setRendererDisabled still fetch the video stream in background, contrary
|
// Disable the video track and the ability to select subtitles
|
||||||
// to setSelectionOverride with a null override.
|
// Use an ArraySet because we can't use Set.of() on all supported APIs by the app
|
||||||
trackSelector.setParameters(trackSelector.buildUponParameters()
|
final ArraySet<Integer> disabledTracks = new ArraySet<>();
|
||||||
.setSelectionOverride(videoRenderIndex, videoTrackGroupArray, null));
|
disabledTracks.add(C.TRACK_TYPE_TEXT);
|
||||||
|
disabledTracks.add(C.TRACK_TYPE_VIDEO);
|
||||||
|
parametersBuilder.setDisabledTrackTypes(disabledTracks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trackSelector.setParameters(parametersBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
setRecovery();
|
setRecovery();
|
||||||
|
|
Loading…
Reference in New Issue