Skip to content

Commit

Permalink
Merge pull request androidx#753 from stevemayhew:p-fix-issue-9347
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 590862514
  • Loading branch information
copybara-github committed Dec 14, 2023
2 parents d52772d + 7a70287 commit ab296ef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
* Fix issue that OPUS and VORBIS channel layouts are wrong for 3, 5, 6, 7
and 8 channels
([#8396](https://github.com/google/ExoPlayer/issues/8396)).
* Fix issue where track selections after seek to zero in a live stream
incorrectly let the stream start at its default position
([#9347](https://github.com/google/ExoPlayer/issues/9347)).
* Transformer:
* Add support for flattening H.265/HEVC SEF slow motion videos.
* Increase transmuxing speed, especially for 'remove video' edits.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ public long selectTracks(
long positionUs) {
if (preparePositionOverrideUs != C.TIME_UNSET && positionUs == preparePositionUs) {
positionUs = preparePositionOverrideUs;
preparePositionOverrideUs = C.TIME_UNSET;
}
preparePositionOverrideUs = C.TIME_UNSET;
return castNonNull(mediaPeriod)
.selectTracks(selections, mayRetainStreamFlags, streams, streamResetFlags, positionUs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import androidx.media3.common.Timeline;
import androidx.media3.common.Timeline.Window;
import androidx.media3.common.TrackGroup;
import androidx.media3.common.TrackSelectionParameters;
import androidx.media3.common.TrackSelectionParameters.AudioOffloadPreferences;
import androidx.media3.common.Tracks;
import androidx.media3.common.VideoSize;
Expand Down Expand Up @@ -14179,6 +14180,53 @@ public PlaybackParameters getPlaybackParameters() {
player.release();
}

@Test
public void seekToZeroAndTrackSelection_withNonZeroDefaultPosition_startsPlaybackAtZero()
throws Exception {
// Create a timeline with a non-zero default position. It's important to use a
// windowOffsetInFirstPeriodUs of zero to ensure that our later manual seek to zero could be
// mistaken for the initial placeholder start position of zero
// (see https://github.com/google/ExoPlayer/issues/9347).
Timeline timeline =
new FakeTimeline(
new TimelineWindowDefinition(
/* periodCount= */ 1,
/* id= */ new Object(),
/* isSeekable= */ true,
/* isDynamic= */ true,
/* isLive= */ true,
/* isPlaceholder= */ false,
/* durationUs= */ 10_000_000,
/* defaultPositionUs= */ 9_000_000,
/* windowOffsetInFirstPeriodUs= */ 0,
/* adPlaybackState= */ AdPlaybackState.NONE));
FakeMediaSource mediaSource =
new FakeMediaSource(
timeline, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT);
// Make sure the player has to use its placeholder values initially.
mediaSource.setAllowPreparation(false);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.setMediaSource(mediaSource);
player.prepare();
runUntilPendingCommandsAreFullyHandled(player);
mediaSource.setAllowPreparation(true);
runUntilPlaybackState(player, Player.STATE_READY);
long positionAfterPrepare = player.getCurrentPosition();

// Manually seek back to zero and force to reselect tracks.
player.seekTo(0);
player.setTrackSelectionParameters(
new TrackSelectionParameters.Builder(context)
.setTrackTypeDisabled(C.TRACK_TYPE_AUDIO, /* disabled= */ true)
.build());
runUntilPendingCommandsAreFullyHandled(player);
long positionAfterSeek = player.getContentPosition();
player.release();

assertThat(positionAfterPrepare).isEqualTo(9000);
assertThat(positionAfterSeek).isEqualTo(0);
}

// Internal methods.

private void addWatchAsSystemFeature() {
Expand Down

0 comments on commit ab296ef

Please sign in to comment.