Skip to content

Commit

Permalink
Merge pull request #753 from stevemayhew:p-fix-issue-9347
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 590862514
(cherry picked from commit ab296ef)
  • Loading branch information
copybara-github authored and microkatz committed Jan 9, 2024
1 parent 33a5190 commit c8a403e
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 @@ -10,6 +10,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:
* Work around an issue where the encoder would throw at configuration time
due to setting a high operating rate.
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 @@ -14101,6 +14102,53 @@ protected void onStreamChanged(
.isSameInstanceAs(mediaItem2);
}

@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 c8a403e

Please sign in to comment.