Properly reset period id and start position in ExoPlayerImpl.

This is a no-op change as the respective values are not used so far but
the change makes the current state cleaner and is less error-prone.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217892421
This commit is contained in:
tonihei 2018-10-19 10:36:35 -07:00 committed by Oliver Woodman
parent 6ae015ecbd
commit 9607c6de1b
3 changed files with 42 additions and 21 deletions

View File

@ -731,20 +731,26 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskingPeriodIndex = getCurrentPeriodIndex();
maskingWindowPositionMs = getCurrentPosition();
}
MediaPeriodId mediaPeriodId =
resetPosition
? playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window)
: playbackInfo.periodId;
long startPositionUs = resetPosition ? 0 : playbackInfo.positionUs;
long contentPositionUs = resetPosition ? C.TIME_UNSET : playbackInfo.contentPositionUs;
return new PlaybackInfo(
resetState ? Timeline.EMPTY : playbackInfo.timeline,
resetState ? null : playbackInfo.manifest,
playbackInfo.periodId,
playbackInfo.startPositionUs,
playbackInfo.contentPositionUs,
mediaPeriodId,
startPositionUs,
contentPositionUs,
playbackState,
/* isLoading= */ false,
resetState ? TrackGroupArray.EMPTY : playbackInfo.trackGroups,
resetState ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult,
playbackInfo.periodId,
playbackInfo.startPositionUs,
mediaPeriodId,
startPositionUs,
/* totalBufferedDurationUs= */ 0,
playbackInfo.startPositionUs);
startPositionUs);
}
private void updatePlaybackInfo(

View File

@ -607,7 +607,7 @@ import java.util.Collections;
if (resolvedSeekPosition == null) {
// The seek position was valid for the timeline that it was performed into, but the
// timeline has changed or is not ready and a suitable seek position could not be resolved.
periodId = getFirstMediaPeriodId();
periodId = playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window);
periodPositionUs = C.TIME_UNSET;
contentPositionUs = C.TIME_UNSET;
seekPositionAdjusted = true;
@ -762,17 +762,6 @@ import java.util.Collections;
}
}
private MediaPeriodId getFirstMediaPeriodId() {
Timeline timeline = playbackInfo.timeline;
if (timeline.isEmpty()) {
return PlaybackInfo.DUMMY_MEDIA_PERIOD_ID;
}
int firstPeriodIndex =
timeline.getWindow(timeline.getFirstWindowIndex(shuffleModeEnabled), window)
.firstPeriodIndex;
return new MediaPeriodId(timeline.getUidOfPeriod(firstPeriodIndex));
}
private void resetInternal(
boolean releaseMediaSource, boolean resetPosition, boolean resetState) {
handler.removeMessages(MSG_DO_SOME_WORK);
@ -801,8 +790,11 @@ import java.util.Collections;
pendingMessages.clear();
nextPendingMessageIndex = 0;
}
MediaPeriodId mediaPeriodId =
resetPosition
? playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window)
: playbackInfo.periodId;
// Set the start position to TIME_UNSET so that a subsequent seek to 0 isn't ignored.
MediaPeriodId mediaPeriodId = resetPosition ? getFirstMediaPeriodId() : playbackInfo.periodId;
long startPositionUs = resetPosition ? C.TIME_UNSET : playbackInfo.positionUs;
long contentPositionUs = resetPosition ? C.TIME_UNSET : playbackInfo.contentPositionUs;
playbackInfo =
@ -1178,8 +1170,13 @@ import java.util.Collections;
periodPosition =
resolveSeekPosition(pendingInitialSeekPosition, /* trySubsequentPeriods= */ true);
} catch (IllegalSeekPositionException e) {
MediaPeriodId firstMediaPeriodId =
playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window);
playbackInfo =
playbackInfo.resetToNewPosition(getFirstMediaPeriodId(), C.TIME_UNSET, C.TIME_UNSET);
playbackInfo.resetToNewPosition(
firstMediaPeriodId,
/* startPositionUs= */ C.TIME_UNSET,
/* contentPositionUs= */ C.TIME_UNSET);
throw e;
}
pendingInitialSeekPosition = null;

View File

@ -30,7 +30,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
* Dummy media period id used while the timeline is empty and no period id is specified. This id
* is used when playback infos are created with {@link #createDummy(long, TrackSelectorResult)}.
*/
public static final MediaPeriodId DUMMY_MEDIA_PERIOD_ID =
private static final MediaPeriodId DUMMY_MEDIA_PERIOD_ID =
new MediaPeriodId(/* periodUid= */ new Object());
/** The current {@link Timeline}. */
@ -151,6 +151,24 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
this.positionUs = positionUs;
}
/**
* Returns dummy media period id for the first-to-be-played period of the current timeline.
*
* @param shuffleModeEnabled Whether shuffle mode is enabled.
* @param window A writable {@link Timeline.Window}.
* @return A dummy media period id for the first-to-be-played period of the current timeline.
*/
public MediaPeriodId getDummyFirstMediaPeriodId(
boolean shuffleModeEnabled, Timeline.Window window) {
if (timeline.isEmpty()) {
return DUMMY_MEDIA_PERIOD_ID;
}
int firstPeriodIndex =
timeline.getWindow(timeline.getFirstWindowIndex(shuffleModeEnabled), window)
.firstPeriodIndex;
return new MediaPeriodId(timeline.getUidOfPeriod(firstPeriodIndex));
}
/**
* Copies playback info and resets playing and loading position.
*