Skip to content

Commit 548c4ce

Browse files
toniheiSheenaChhabra
authored andcommitted
Fix HlsPlaybackTest flakiness
The new test introduced in 45bd5c6 is flaky because we only wait until the media is fully buffered. However, we can't fully control how much of this data is initially read by the Robolectric codec and thus the output dump files (containing these codec interactions) are flaky. This can be fixed by fully playing the media once and then seeking back instead. #minor-release PiperOrigin-RevId: 603324068 (cherry picked from commit e3e57c9)
1 parent 7758e42 commit 548c4ce

File tree

2 files changed

+591
-84
lines changed

2 files changed

+591
-84
lines changed

‎libraries/exoplayer_hls/src/test/java/androidx/media3/exoplayer/hls/e2etest/HlsPlaybackTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import androidx.media3.common.MediaItem;
2323
import androidx.media3.common.Player;
2424
import androidx.media3.datasource.DefaultDataSource;
25+
import androidx.media3.exoplayer.DefaultLoadControl;
2526
import androidx.media3.exoplayer.ExoPlayer;
2627
import androidx.media3.exoplayer.SeekParameters;
2728
import androidx.media3.exoplayer.hls.HlsMediaSource;
@@ -167,14 +168,19 @@ public void multiSegment_withSeekToPrevSyncFrame_startsRenderingAtBeginningOfSeg
167168
new HlsMediaSource.Factory(new DefaultDataSource.Factory(applicationContext))
168169
.experimentalParseSubtitlesDuringExtraction(true))
169170
.setClock(new FakeClock(/* isAutoAdvancing= */ true))
171+
.setLoadControl(
172+
new DefaultLoadControl.Builder()
173+
.setBackBuffer(
174+
/* backBufferDurationMs= */ 10000, /* retainBackBufferFromKeyframe= */ true)
175+
.build())
170176
.build();
171-
// Prepare media fully to ensure we have all the segment data available.
172177
player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */ 1)));
173178
PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
179+
// Play media fully (with back buffer) to ensure we have all the segment data available.
174180
player.setMediaItem(MediaItem.fromUri("asset:///media/hls/multi-segment/playlist.m3u8"));
175181
player.prepare();
176-
TestPlayerRunHelper.runUntilIsLoading(player, true);
177-
TestPlayerRunHelper.runUntilIsLoading(player, false);
182+
player.play();
183+
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
178184

179185
// Seek to beginning of second segment (at 500ms according to playlist)
180186
player.setSeekParameters(SeekParameters.PREVIOUS_SYNC);

0 commit comments

Comments
 (0)