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(); maskingPeriodIndex = getCurrentPeriodIndex();
maskingWindowPositionMs = getCurrentPosition(); 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( return new PlaybackInfo(
resetState ? Timeline.EMPTY : playbackInfo.timeline, resetState ? Timeline.EMPTY : playbackInfo.timeline,
resetState ? null : playbackInfo.manifest, resetState ? null : playbackInfo.manifest,
playbackInfo.periodId, mediaPeriodId,
playbackInfo.startPositionUs, startPositionUs,
playbackInfo.contentPositionUs, contentPositionUs,
playbackState, playbackState,
/* isLoading= */ false, /* isLoading= */ false,
resetState ? TrackGroupArray.EMPTY : playbackInfo.trackGroups, resetState ? TrackGroupArray.EMPTY : playbackInfo.trackGroups,
resetState ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult, resetState ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult,
playbackInfo.periodId, mediaPeriodId,
playbackInfo.startPositionUs, startPositionUs,
/* totalBufferedDurationUs= */ 0, /* totalBufferedDurationUs= */ 0,
playbackInfo.startPositionUs); startPositionUs);
} }
private void updatePlaybackInfo( private void updatePlaybackInfo(

View File

@ -607,7 +607,7 @@ import java.util.Collections;
if (resolvedSeekPosition == null) { if (resolvedSeekPosition == null) {
// The seek position was valid for the timeline that it was performed into, but the // 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. // 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; periodPositionUs = C.TIME_UNSET;
contentPositionUs = C.TIME_UNSET; contentPositionUs = C.TIME_UNSET;
seekPositionAdjusted = true; 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( private void resetInternal(
boolean releaseMediaSource, boolean resetPosition, boolean resetState) { boolean releaseMediaSource, boolean resetPosition, boolean resetState) {
handler.removeMessages(MSG_DO_SOME_WORK); handler.removeMessages(MSG_DO_SOME_WORK);
@ -801,8 +790,11 @@ import java.util.Collections;
pendingMessages.clear(); pendingMessages.clear();
nextPendingMessageIndex = 0; 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. // 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 startPositionUs = resetPosition ? C.TIME_UNSET : playbackInfo.positionUs;
long contentPositionUs = resetPosition ? C.TIME_UNSET : playbackInfo.contentPositionUs; long contentPositionUs = resetPosition ? C.TIME_UNSET : playbackInfo.contentPositionUs;
playbackInfo = playbackInfo =
@ -1178,8 +1170,13 @@ import java.util.Collections;
periodPosition = periodPosition =
resolveSeekPosition(pendingInitialSeekPosition, /* trySubsequentPeriods= */ true); resolveSeekPosition(pendingInitialSeekPosition, /* trySubsequentPeriods= */ true);
} catch (IllegalSeekPositionException e) { } catch (IllegalSeekPositionException e) {
MediaPeriodId firstMediaPeriodId =
playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window);
playbackInfo = playbackInfo =
playbackInfo.resetToNewPosition(getFirstMediaPeriodId(), C.TIME_UNSET, C.TIME_UNSET); playbackInfo.resetToNewPosition(
firstMediaPeriodId,
/* startPositionUs= */ C.TIME_UNSET,
/* contentPositionUs= */ C.TIME_UNSET);
throw e; throw e;
} }
pendingInitialSeekPosition = null; 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 * 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)}. * 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()); new MediaPeriodId(/* periodUid= */ new Object());
/** The current {@link Timeline}. */ /** The current {@link Timeline}. */
@ -151,6 +151,24 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
this.positionUs = positionUs; 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. * Copies playback info and resets playing and loading position.
* *