TestPlayerRunHelper
@UnstableApi
public final class TestPlayerRunHelper
Helper methods to block the calling thread until the provided ExoPlayer instance reaches a particular state.
This class has two usage modes:
- Fluent method chaining, e.g.
run(player).ignoringNonFatalErrors().untilState(STATE_ENDED). - Single method call, e.g.
runUntilPlaybackState(player, STATE_ENDED).
New usages should prefer the fluent method chaining, and new functionality will only be added to this form. The older single methods will be kept for backwards compatibility.
Summary
Nested types |
|---|
public final class TestPlayerRunHelper.CompositionPlayerRunResult extends TestPlayerRunHelper.PlayerRunResultA |
public final class TestPlayerRunHelper.ExoPlayerRunResult extends TestPlayerRunHelper.PlayerRunResultAn |
public class TestPlayerRunHelper.PlayerRunResultIntermediate type that allows callers to run the main |
Public methods |
|
|---|---|
static TestPlayerRunHelper.CompositionPlayerRunResult |
advance(CompositionPlayer player)Entry point for a fluent "wait for condition X" assertion. |
static TestPlayerRunHelper.ExoPlayerRunResult |
Entry point for a fluent "wait for condition X" assertion. |
static TestPlayerRunHelper.PlayerRunResult |
Entry point for a fluent "wait for condition X" assertion. |
static TestPlayerRunHelper.CompositionPlayerRunResult |
play(CompositionPlayer player)Entry point for a fluent "start playback and wait for condition X" assertion. |
static TestPlayerRunHelper.ExoPlayerRunResult |
Entry point for a fluent "start playback and wait for condition X" assertion. |
static TestPlayerRunHelper.PlayerRunResult |
Entry point for a fluent "start playback and wait for condition X" assertion. |
static void |
playUntilPosition(ExoPlayer player, int mediaItemIndex, long positionMs)Calls |
static void |
playUntilStartOfMediaItem(ExoPlayer player, int mediaItemIndex)Calls |
static TestPlayerRunHelper.ExoPlayerRunResult |
@InlineMe(replacement = "TestPlayerRunHelper.advance(player)", imports = "androidx.media3.test.utils.robolectric.TestPlayerRunHelper")This method is deprecated. Use |
static TestPlayerRunHelper.PlayerRunResult |
@InlineMe(replacement = "TestPlayerRunHelper.advance(player)", imports = "androidx.media3.test.utils.robolectric.TestPlayerRunHelper")This method is deprecated. Use |
static ExoPlaybackException |
runUntilError(ExoPlayer player)Runs tasks of the main |
static void |
runUntilIsLoading(Player player, boolean expectedIsLoading)Runs tasks of the main |
static void |
Runs tasks of the main |
static void |
runUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady)Runs tasks of the main |
static void |
runUntilPlaybackState(Player player, @Player.State int expectedState)Runs tasks of the main |
static void |
runUntilPositionDiscontinuity(Runs tasks of the main |
static void |
runUntilRenderedFirstFrame(ExoPlayer player)Runs tasks of the main |
static void |
runUntilSleepingForOffload(Runs tasks of the main |
static Timeline |
runUntilTimelineChanged(Player player)Runs tasks of the main |
static void |
runUntilTimelineChanged(Player player, Timeline expectedTimeline)Runs tasks of the main |
Public methods
advance
public static TestPlayerRunHelper.CompositionPlayerRunResult advance(CompositionPlayer player)
Entry point for a fluent "wait for condition X" assertion.
Callers can use the returned CompositionPlayerRunResult to run the main Looper until certain conditions are met.
advance
public static TestPlayerRunHelper.ExoPlayerRunResult advance(ExoPlayer player)
Entry point for a fluent "wait for condition X" assertion.
Callers can use the returned ExoPlayerRunResult to run the main Looper until certain conditions are met.
advance
public static TestPlayerRunHelper.PlayerRunResult advance(Player player)
Entry point for a fluent "wait for condition X" assertion.
Callers can use the returned PlayerRunResult to run the main Looper until certain conditions are met.
play
public static TestPlayerRunHelper.CompositionPlayerRunResult play(CompositionPlayer player)
Entry point for a fluent "start playback and wait for condition X" assertion.
Callers can use the returned CompositionPlayerRunResult to run the main Looper until certain conditions are met.
This is the same as advance but ensures play is called before waiting in subsequent untilXXX(...) methods.
play
public static TestPlayerRunHelper.ExoPlayerRunResult play(ExoPlayer player)
Entry point for a fluent "start playback and wait for condition X" assertion.
Callers can use the returned ExoPlayerRunResult to run the main Looper until certain conditions are met.
This is the same as advance but ensures play is called before waiting in subsequent untilXXX(...) methods.
play
public static TestPlayerRunHelper.PlayerRunResult play(Player player)
Entry point for a fluent "start playback and wait for condition X" assertion.
Callers can use the returned PlayerRunResult to run the main Looper until certain conditions are met.
This is the same as advance but ensures play is called before waiting in subsequent untilXXX(...) methods.
playUntilPosition
public static void playUntilPosition(ExoPlayer player, int mediaItemIndex, long positionMs)
Calls play then runs tasks of the main Looper until the internal playback thread of the player reaches the specified position or an error occurs.
Use advance and untilPositionAtLeast instead if the test needs to advance the player until the publicly visible position reaches a specified value.
The playback thread is automatically blocked from making further progress after reaching this position and will only be unblocked by other runUntil/playUntil... methods, custom runMainLooperUntil conditions or an explicit unblockThreadsWaitingForProgressOnCurrentLooper on the main thread.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilPosition.
| Parameters | |
|---|---|
ExoPlayer player |
The |
int mediaItemIndex |
The index of the media item. |
long positionMs |
The position within the media item, in milliseconds. |
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
playUntilStartOfMediaItem
public static void playUntilStartOfMediaItem(ExoPlayer player, int mediaItemIndex)
Calls play then runs tasks of the main Looper until the internal playback thread of the player reaches the start of the specified media item or a playback error occurs.
Use advance and untilMediaItemIndex instead if the test needs to advance the player until the publicly visible media item index reaches a specified value.
The playback thread is automatically blocked from making further progress after reaching the media item and will only be unblocked by other runUntil/playUntil... methods, custom runMainLooperUntil conditions or an explicit unblockThreadsWaitingForProgressOnCurrentLooper on the main thread.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilStartOfMediaItem.
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
run
@InlineMe(replacement = "TestPlayerRunHelper.advance(player)", imports = "androidx.media3.test.utils.robolectric.TestPlayerRunHelper")
public static TestPlayerRunHelper.ExoPlayerRunResultrun(ExoPlayer player)
run
@InlineMe(replacement = "TestPlayerRunHelper.advance(player)", imports = "androidx.media3.test.utils.robolectric.TestPlayerRunHelper")
public static TestPlayerRunHelper.PlayerRunResultrun(Player player)
runUntilError
public static ExoPlaybackException runUntilError(ExoPlayer player)
Runs tasks of the main Looper until a player error occurs.
Non-fatal errors are ignored.
New usages should prefer advance and untilPlayerError.
| Returns | |
|---|---|
ExoPlaybackException |
The raised |
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilIsLoading
public static void runUntilIsLoading(Player player, boolean expectedIsLoading)
Runs tasks of the main Looper until isLoading matches the expected value or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilLoadingIs.
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilPendingCommandsAreFullyHandled
public static void runUntilPendingCommandsAreFullyHandled(ExoPlayer player)
Runs tasks of the main Looper until the player completely handled all previously issued commands on the internal playback thread.
Both fatal and non-fatal errors are ignored.
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilPlayWhenReady
public static void runUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady)
Runs tasks of the main Looper until getPlayWhenReady matches the expected value or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilPlayWhenReadyIs.
| Parameters | |
|---|---|
Player player |
The |
boolean expectedPlayWhenReady |
The expected value for |
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilPlaybackState
public static void runUntilPlaybackState(Player player, @Player.State int expectedState)
Runs tasks of the main Looper until getPlaybackState matches the expected state or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilState.
| Parameters | |
|---|---|
Player player |
The |
@Player.State int expectedState |
The expected |
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilPositionDiscontinuity
public static void runUntilPositionDiscontinuity(
Player player,
@Player.DiscontinuityReason int expectedReason
)
Runs tasks of the main Looper until onPositionDiscontinuity is called with the specified Player.DiscontinuityReason or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilPositionDiscontinuityWithReason.
| Parameters | |
|---|---|
Player player |
The |
@Player.DiscontinuityReason int expectedReason |
The expected |
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilRenderedFirstFrame
public static void runUntilRenderedFirstFrame(ExoPlayer player)
Runs tasks of the main Looper until onRenderedFirstFrame is called or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilFirstFrameIsRendered.
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilSleepingForOffload
public static void runUntilSleepingForOffload(
ExoPlayer player,
boolean expectedSleepForOffload
)
Runs tasks of the main Looper until isSleepingForOffload matches the expected value, or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilSleepingForOffloadBecomes.
| Parameters | |
|---|---|
ExoPlayer player |
The |
boolean expectedSleepForOffload |
The expected sleep of offload state. |
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilTimelineChanged
public static Timeline runUntilTimelineChanged(Player player)
Runs tasks of the main Looper until a timeline change or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilTimelineChanges.
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |
runUntilTimelineChanged
public static void runUntilTimelineChanged(Player player, Timeline expectedTimeline)
Runs tasks of the main Looper until getCurrentTimeline matches the expected timeline or an error occurs.
If a fatal PlaybackException occurs it will be thrown wrapped in an IllegalStateException.
New usages should prefer advance and untilTimelineChangesTo.
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the |