Commit 108a7099 by tonihei Committed by Oliver Woodman

Add missing calls to LoadControl.onTracksSelected.

This method needs to be called whenever the track selection of the current
loading period changes, but also when the loading period itself (and thus
the "loading track selection") changes. These are the same situations in which
we update the loading media period id and thus we can move both updates in
a common helper method.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=213959982
parent edf7561b
...@@ -428,7 +428,7 @@ import java.util.Collections; ...@@ -428,7 +428,7 @@ import java.util.Collections;
if (!queue.updateRepeatMode(repeatMode)) { if (!queue.updateRepeatMode(repeatMode)) {
seekToCurrentPosition(/* sendDiscontinuity= */ true); seekToCurrentPosition(/* sendDiscontinuity= */ true);
} }
updateLoadingMediaPeriodId(); handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false);
} }
private void setShuffleModeEnabledInternal(boolean shuffleModeEnabled) private void setShuffleModeEnabledInternal(boolean shuffleModeEnabled)
...@@ -437,7 +437,7 @@ import java.util.Collections; ...@@ -437,7 +437,7 @@ import java.util.Collections;
if (!queue.updateShuffleModeEnabled(shuffleModeEnabled)) { if (!queue.updateShuffleModeEnabled(shuffleModeEnabled)) {
seekToCurrentPosition(/* sendDiscontinuity= */ true); seekToCurrentPosition(/* sendDiscontinuity= */ true);
} }
updateLoadingMediaPeriodId(); handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false);
} }
private void seekToCurrentPosition(boolean sendDiscontinuity) throws ExoPlaybackException { private void seekToCurrentPosition(boolean sendDiscontinuity) throws ExoPlaybackException {
...@@ -706,7 +706,7 @@ import java.util.Collections; ...@@ -706,7 +706,7 @@ import java.util.Collections;
resetRendererPosition(periodPositionUs); resetRendererPosition(periodPositionUs);
} }
updateLoadingMediaPeriodId(); handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false);
handler.sendEmptyMessage(MSG_DO_SOME_WORK); handler.sendEmptyMessage(MSG_DO_SOME_WORK);
return periodPositionUs; return periodPositionUs;
} }
...@@ -1018,8 +1018,6 @@ import java.util.Collections; ...@@ -1018,8 +1018,6 @@ import java.util.Collections;
long periodPositionUs = long periodPositionUs =
playingPeriodHolder.applyTrackSelection( playingPeriodHolder.applyTrackSelection(
playbackInfo.positionUs, recreateStreams, streamResetFlags); playbackInfo.positionUs, recreateStreams, streamResetFlags);
updateLoadControlTrackSelection(
playingPeriodHolder.trackGroups, playingPeriodHolder.trackSelectorResult);
if (playbackInfo.playbackState != Player.STATE_ENDED if (playbackInfo.playbackState != Player.STATE_ENDED
&& periodPositionUs != playbackInfo.positionUs) { && periodPositionUs != playbackInfo.positionUs) {
playbackInfo = playbackInfo.fromNewPosition(playbackInfo.periodId, periodPositionUs, playbackInfo = playbackInfo.fromNewPosition(playbackInfo.periodId, periodPositionUs,
...@@ -1059,10 +1057,9 @@ import java.util.Collections; ...@@ -1059,10 +1057,9 @@ import java.util.Collections;
Math.max( Math.max(
periodHolder.info.startPositionUs, periodHolder.toPeriodTime(rendererPositionUs)); periodHolder.info.startPositionUs, periodHolder.toPeriodTime(rendererPositionUs));
periodHolder.applyTrackSelection(loadingPeriodPositionUs, false); periodHolder.applyTrackSelection(loadingPeriodPositionUs, false);
updateLoadControlTrackSelection(periodHolder.trackGroups, periodHolder.trackSelectorResult);
} }
} }
updateLoadingMediaPeriodId(); handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ true);
if (playbackInfo.playbackState != Player.STATE_ENDED) { if (playbackInfo.playbackState != Player.STATE_ENDED) {
maybeContinueLoading(); maybeContinueLoading();
updatePlaybackPositions(); updatePlaybackPositions();
...@@ -1070,11 +1067,6 @@ import java.util.Collections; ...@@ -1070,11 +1067,6 @@ import java.util.Collections;
} }
} }
private void updateLoadControlTrackSelection(
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections);
}
private void updateTrackSelectionPlaybackSpeed(float playbackSpeed) { private void updateTrackSelectionPlaybackSpeed(float playbackSpeed) {
MediaPeriodHolder periodHolder = queue.getFrontPeriod(); MediaPeriodHolder periodHolder = queue.getFrontPeriod();
while (periodHolder != null) { while (periodHolder != null) {
...@@ -1278,7 +1270,7 @@ import java.util.Collections; ...@@ -1278,7 +1270,7 @@ import java.util.Collections;
if (!queue.updateQueuedPeriods(playingPeriodId, rendererPositionUs)) { if (!queue.updateQueuedPeriods(playingPeriodId, rendererPositionUs)) {
seekToCurrentPosition(/* sendDiscontinuity= */ false); seekToCurrentPosition(/* sendDiscontinuity= */ false);
} }
updateLoadingMediaPeriodId(); handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false);
} }
private void handleSourceInfoRefreshEndedPlayback() { private void handleSourceInfoRefreshEndedPlayback() {
...@@ -1528,7 +1520,7 @@ import java.util.Collections; ...@@ -1528,7 +1520,7 @@ import java.util.Collections;
info); info);
mediaPeriod.prepare(this, info.startPositionUs); mediaPeriod.prepare(this, info.startPositionUs);
setIsLoading(true); setIsLoading(true);
updateLoadingMediaPeriodId(); handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false);
} }
} }
} }
...@@ -1666,14 +1658,28 @@ import java.util.Collections; ...@@ -1666,14 +1658,28 @@ import java.util.Collections;
&& renderer.hasReadStreamToEnd(); && renderer.hasReadStreamToEnd();
} }
private void updateLoadingMediaPeriodId() { private void handleLoadingMediaPeriodChanged(boolean loadingTrackSelectionChanged) {
MediaPeriodHolder loadingMediaPeriodHolder = queue.getLoadingPeriod(); MediaPeriodHolder loadingMediaPeriodHolder = queue.getLoadingPeriod();
MediaPeriodId loadingMediaPeriodId = MediaPeriodId loadingMediaPeriodId =
loadingMediaPeriodHolder == null ? playbackInfo.periodId : loadingMediaPeriodHolder.info.id; loadingMediaPeriodHolder == null ? playbackInfo.periodId : loadingMediaPeriodHolder.info.id;
boolean loadingMediaPeriodChanged =
!playbackInfo.loadingMediaPeriodId.equals(loadingMediaPeriodId);
if (loadingMediaPeriodChanged) {
playbackInfo = playbackInfo.copyWithLoadingMediaPeriodId(loadingMediaPeriodId); playbackInfo = playbackInfo.copyWithLoadingMediaPeriodId(loadingMediaPeriodId);
} }
if ((loadingMediaPeriodChanged || loadingTrackSelectionChanged)
&& loadingMediaPeriodHolder != null
&& loadingMediaPeriodHolder.prepared) {
updateLoadControlTrackSelection(
loadingMediaPeriodHolder.trackGroups, loadingMediaPeriodHolder.trackSelectorResult);
}
}
private void updateLoadControlTrackSelection(
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections);
}
@NonNull
private static Format[] getFormats(TrackSelection newSelection) { private static Format[] getFormats(TrackSelection newSelection) {
// Build an array of formats contained by the selection. // Build an array of formats contained by the selection.
int length = newSelection != null ? newSelection.length() : 0; int length = newSelection != null ? newSelection.length() : 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment