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

An ExoPlayer specific subclass of PlayerRunResult, giving access to conditions that only make sense for the ExoPlayer interface.

Intermediate type that allows callers to run the main Looper until certain conditions are met.

Public functions

java-static TestPlayerRunHelper.ExoPlayerRunResult!
play(player: ExoPlayer!)

Entry point for a fluent "start playback and wait for condition X" assertion.

java-static TestPlayerRunHelper.PlayerRunResult!
play(player: Player!)

Entry point for a fluent "start playback and wait for condition X" assertion.

java-static Unit
playUntilPosition(player: ExoPlayer!, mediaItemIndex: Int, positionMs: Long)

Calls play then runs tasks of the main Looper until the player reaches the specified position or an error occurs.

java-static Unit
playUntilStartOfMediaItem(player: ExoPlayer!, mediaItemIndex: Int)

Calls play then runs tasks of the main Looper until the player reaches the specified media item or a playback error occurs.

java-static TestPlayerRunHelper.ExoPlayerRunResult!
run(player: ExoPlayer!)

Entry point for a fluent "wait for condition X" assertion.

java-static TestPlayerRunHelper.PlayerRunResult!
run(player: Player!)

Entry point for a fluent "wait for condition X" assertion.

java-static ExoPlaybackException!

Runs tasks of the main Looper until a player error occurs.

java-static Unit
runUntilIsLoading(player: Player!, expectedIsLoading: Boolean)

Runs tasks of the main Looper until isLoading matches the expected value or an error occurs.

java-static Unit

Runs tasks of the main Looper until the player completely handled all previously issued commands on the internal playback thread.

java-static Unit
runUntilPlayWhenReady(player: Player!, expectedPlayWhenReady: Boolean)

Runs tasks of the main Looper until getPlayWhenReady matches the expected value or an error occurs.

java-static Unit
runUntilPlaybackState(player: Player!, @Player.State expectedState: Int)

Runs tasks of the main Looper until getPlaybackState matches the expected state or an error occurs.

java-static Unit
runUntilPositionDiscontinuity(
    player: Player!,
    @Player.DiscontinuityReason expectedReason: Int
)

Runs tasks of the main Looper until onPositionDiscontinuity is called with the specified Player.DiscontinuityReason or an error occurs.

java-static Unit

Runs tasks of the main Looper until onRenderedFirstFrame is called or an error occurs.

java-static Unit
runUntilSleepingForOffload(
    player: ExoPlayer!,
    expectedSleepForOffload: Boolean
)

Runs tasks of the main Looper until isSleepingForOffload matches the expected value, or an error occurs.

java-static Timeline!

Runs tasks of the main Looper until a timeline change or an error occurs.

java-static Unit
runUntilTimelineChanged(player: Player!, expectedTimeline: Timeline!)

Runs tasks of the main Looper until getCurrentTimeline matches the expected timeline or an error occurs.

Public functions

play

java-static fun play(player: ExoPlayer!): TestPlayerRunHelper.ExoPlayerRunResult!

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 run but ensures play is called before waiting in subsequent untilXXX(...) methods.

play

java-static fun play(player: Player!): TestPlayerRunHelper.PlayerRunResult!

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 run but ensures play is called before waiting in subsequent untilXXX(...) methods.

playUntilPosition

java-static fun playUntilPosition(player: ExoPlayer!, mediaItemIndex: Int, positionMs: Long): Unit

Calls play then runs tasks of the main Looper until the player reaches the specified position or an error occurs.

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 .

New usages should prefer run and untilPosition.

Parameters
player: ExoPlayer!

The Player.

mediaItemIndex: Int

The index of the media item.

positionMs: Long

The position within the media item, in milliseconds.

playUntilStartOfMediaItem

java-static fun playUntilStartOfMediaItem(player: ExoPlayer!, mediaItemIndex: Int): Unit

Calls play then runs tasks of the main Looper until the player reaches the specified media item or a playback error occurs.

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 .

New usages should prefer run and untilStartOfMediaItem.

Parameters
player: ExoPlayer!

The Player.

mediaItemIndex: Int

The index of the media item.

run

java-static fun run(player: ExoPlayer!): TestPlayerRunHelper.ExoPlayerRunResult!

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.

run

java-static fun run(player: Player!): TestPlayerRunHelper.PlayerRunResult!

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.

runUntilError

java-static fun runUntilError(player: ExoPlayer!): ExoPlaybackException!

Runs tasks of the main Looper until a player error occurs.

Non-fatal errors are ignored.

New usages should prefer run and untilPlayerError.

Parameters
player: ExoPlayer!

The Player.

runUntilIsLoading

java-static fun runUntilIsLoading(player: Player!, expectedIsLoading: Boolean): Unit

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 .

New usages should prefer run and untilLoadingIs.

Parameters
player: Player!

The Player.

expectedIsLoading: Boolean

The expected value for isLoading.

runUntilPendingCommandsAreFullyHandled

java-static fun runUntilPendingCommandsAreFullyHandled(player: ExoPlayer!): Unit

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.

Parameters
player: ExoPlayer!

The Player.

runUntilPlayWhenReady

java-static fun runUntilPlayWhenReady(player: Player!, expectedPlayWhenReady: Boolean): Unit

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 .

New usages should prefer run and untilPlayWhenReadyIs.

Parameters
player: Player!

The Player.

expectedPlayWhenReady: Boolean

The expected value for getPlayWhenReady.

runUntilPlaybackState

java-static fun runUntilPlaybackState(player: Player!, @Player.State expectedState: Int): Unit

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 .

New usages should prefer run and untilState.

Parameters
player: Player!

The Player.

@Player.State expectedState: Int

The expected Player.State.

runUntilPositionDiscontinuity

java-static fun runUntilPositionDiscontinuity(
    player: Player!,
    @Player.DiscontinuityReason expectedReason: Int
): Unit

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 .

New usages should prefer run and untilPositionDiscontinuityWithReason.

Parameters
player: Player!

The Player.

@Player.DiscontinuityReason expectedReason: Int

The expected Player.DiscontinuityReason.

runUntilRenderedFirstFrame

java-static fun runUntilRenderedFirstFrame(player: ExoPlayer!): Unit

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 .

New usages should prefer run and untilFirstFrameIsRendered.

Parameters
player: ExoPlayer!

The Player.

runUntilSleepingForOffload

java-static fun runUntilSleepingForOffload(
    player: ExoPlayer!,
    expectedSleepForOffload: Boolean
): Unit

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 .

New usages should prefer run and untilSleepingForOffloadBecomes.

Parameters
player: ExoPlayer!

The Player.

expectedSleepForOffload: Boolean

The expected sleep of offload state.

runUntilTimelineChanged

java-static fun runUntilTimelineChanged(player: Player!): Timeline!

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 .

New usages should prefer run and untilTimelineChanges.

Parameters
player: Player!

The Player.

Returns
Timeline!

The new Timeline.

runUntilTimelineChanged

java-static fun runUntilTimelineChanged(player: Player!, expectedTimeline: Timeline!): Unit

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 .

New usages should prefer run and untilTimelineChangesTo.

Parameters
player: Player!

The Player.

expectedTimeline: Timeline!

The expected Timeline.