@UnstableApi
public class TestPlayerRunHelper


Helper methods to block the calling thread until the provided ExoPlayer instance reaches a particular state.

Summary

Public methods

static void
playUntilPosition(ExoPlayer player, int mediaItemIndex, long positionMs)

Calls play, runs tasks of the main Looper until the player reaches the specified position or a playback error occurs.

static void
playUntilStartOfMediaItem(ExoPlayer player, int mediaItemIndex)

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

static ExoPlaybackException

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

static void
runUntilIsLoading(Player player, boolean expectedIsLoading)

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

static void

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

static void
runUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady)

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

static void
runUntilPlaybackState(Player player, @Player.State int expectedState)

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

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 a playback error occurs.

static void

Runs tasks of the main Looper until the onRenderedFirstFrame callback is called or a playback error occurs.

static void
runUntilSleepingForOffload(
    ExoPlayer player,
    boolean expectedSleepForOffload
)

Runs tasks of the main Looper until onSleepingForOffloadChanged is called or a playback error occurs.

static Timeline

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

static void
runUntilTimelineChanged(Player player, Timeline expectedTimeline)

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

Public methods

playUntilPosition

public static void playUntilPosition(ExoPlayer player, int mediaItemIndex, long positionMs)

Calls play, runs tasks of the main Looper until the player reaches the specified position or a playback error occurs.

The playback thread is automatically blocked from making further progress after reaching this position and will only be unblocked by other run/playUntil... methods, custom runMainLooperUntil conditions or an explicit unblockThreadsWaitingForProgressOnCurrentLooper on the main thread.

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
ExoPlayer player

The Player.

int mediaItemIndex

The index of the media item.

long positionMs

The position within the media item, in milliseconds.

playUntilStartOfMediaItem

public static void playUntilStartOfMediaItem(ExoPlayer player, int mediaItemIndex)

Calls play, 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 run/playUntil... methods, custom runMainLooperUntil conditions or an explicit unblockThreadsWaitingForProgressOnCurrentLooper on the main thread.

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
ExoPlayer player

The Player.

int mediaItemIndex

The index of the media item.

runUntilError

public static ExoPlaybackException runUntilError(ExoPlayer player)

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

Parameters
ExoPlayer player

The Player.

runUntilIsLoading

public static void runUntilIsLoading(Player player, boolean expectedIsLoading)

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

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
Player player

The Player.

boolean expectedIsLoading

The expected value for isLoading.

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.

Parameters
ExoPlayer player

The Player.

runUntilPlayWhenReady

public static void runUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady)

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

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
Player player

The Player.

boolean expectedPlayWhenReady

The expected value for getPlayWhenReady.

runUntilPlaybackState

public static void runUntilPlaybackState(Player player, @Player.State int expectedState)

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

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
Player player

The Player.

@Player.State int expectedState

The expected Player.State.

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 a playback error occurs.

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
Player player

The Player.

@Player.DiscontinuityReason int expectedReason

The expected Player.DiscontinuityReason.

runUntilRenderedFirstFrame

public static void runUntilRenderedFirstFrame(ExoPlayer player)

Runs tasks of the main Looper until the onRenderedFirstFrame callback is called or a playback error occurs.

If a playback error occurs it will be thrown wrapped in an IllegalStateException..

Parameters
ExoPlayer player

The Player.

runUntilSleepingForOffload

public static void runUntilSleepingForOffload(
    ExoPlayer player,
    boolean expectedSleepForOffload
)

Runs tasks of the main Looper until onSleepingForOffloadChanged is called or a playback error occurs.

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
ExoPlayer player

The Player.

boolean expectedSleepForOffload

The expected sleep of offload state.

runUntilTimelineChanged

public static Timeline runUntilTimelineChanged(Player player)

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

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
Player player

The Player.

Returns
Timeline

The new Timeline.

runUntilTimelineChanged

public static void runUntilTimelineChanged(Player player, Timeline expectedTimeline)

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

If a playback error occurs it will be thrown wrapped in an IllegalStateException.

Parameters
Player player

The Player.

Timeline expectedTimeline

The expected Timeline.