Package com.google.android.exoplayer2.robolectric

## Class TestPlayerRunHelper

- java.lang.Object
- - com.google.android.exoplayer2.robolectric.TestPlayerRunHelper

-     public class TestPlayerRunHelper
      extends Object

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

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `playUntilPosition​(ExoPlayer player, int windowIndex, long positionMs)` | Calls `Player.play()`, runs tasks of the main `Looper` until the `player` reaches the specified position or a playback error occurs, and then pauses the `player`.
    `static void` | `playUntilStartOfWindow​(ExoPlayer player, int windowIndex)` | Calls `Player.play()`, runs tasks of the main `Looper` until the `player` reaches the specified window or a playback error occurs, and then pauses the `player`.
    `static ExoPlaybackException` | `runUntilError​(ExoPlayer player)` | Runs tasks of the main `Looper` until a player error occurs.
    `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.
    `static void` | `runUntilPlaybackState​(Player player, int expectedState)` | Runs tasks of the main `Looper` until `Player.getPlaybackState()` matches the expected state or a playback error occurs.
    `static void` | `runUntilPlayWhenReady​(Player player, boolean expectedPlayWhenReady)` | Runs tasks of the main `Looper` until `Player.getPlayWhenReady()` matches the expected value or a playback error occurs.
    `static void` | `runUntilPositionDiscontinuity​(Player player, int expectedReason)` | Runs tasks of the main `Looper` until `Player.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)` is called with the specified `Player.DiscontinuityReason` or a playback error occurs.
    `static boolean` | `runUntilReceiveOffloadSchedulingEnabledNewState​(ExoPlayer player)` | Runs tasks of the main `Looper` until `ExoPlayer.AudioOffloadListener.onExperimentalOffloadSchedulingEnabledChanged(boolean)` is called or a playback error occurs.
    `static void` | `runUntilRenderedFirstFrame​(SimpleExoPlayer player)` | Runs tasks of the main `Looper` until the `VideoListener.onRenderedFirstFrame()` callback is called or a playback error occurs.
    `static void` | `runUntilSleepingForOffload​(ExoPlayer player, boolean expectedSleepForOffload)` | Runs tasks of the main `Looper` until `ExoPlayer.AudioOffloadListener.onExperimentalSleepingForOffloadChanged(boolean)` is called or a playback error occurs.
    `static Timeline` | `runUntilTimelineChanged​(Player player)` | 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 `Player.getCurrentTimeline()` matches the expected timeline or a playback error occurs.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### runUntilPlaybackState

          public static void runUntilPlaybackState​(Player player,
                                                   @State
                                                   int expectedState)
                                            throws TimeoutException

      Runs tasks of the main `Looper` until `Player.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` - The `Player`.
        `expectedState` - The expected `Player.State`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilPlayWhenReady

          public static void runUntilPlayWhenReady​(Player player,
                                                   boolean expectedPlayWhenReady)
                                            throws TimeoutException

      Runs tasks of the main `Looper` until `Player.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` - The `Player`.
        `expectedPlayWhenReady` - The expected value for `Player.getPlayWhenReady()`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilTimelineChanged

          public static void runUntilTimelineChanged​(Player player,
                                                     Timeline expectedTimeline)
                                              throws TimeoutException

      Runs tasks of the main `Looper` until `Player.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` - The `Player`.
        `expectedTimeline` - The expected `Timeline`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilTimelineChanged

          public static Timeline runUntilTimelineChanged​(Player player)
                                                  throws TimeoutException

      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` - The `Player`.
      Returns:
        The new `Timeline`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilPositionDiscontinuity

          public static void runUntilPositionDiscontinuity​(Player player,
                                                           @DiscontinuityReason
                                                           int expectedReason)
                                                    throws TimeoutException

      Runs tasks of the main `Looper` until `Player.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)` 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` - The `Player`.
        `expectedReason` - The expected `Player.DiscontinuityReason`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilError

          public static ExoPlaybackException runUntilError​(ExoPlayer player)
                                                    throws TimeoutException

      Runs tasks of the main `Looper` until a player error occurs.
      Parameters:
        `player` - The `Player`.
      Returns:
        The raised `ExoPlaybackException`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilReceiveOffloadSchedulingEnabledNewState

          public static boolean runUntilReceiveOffloadSchedulingEnabledNewState​(ExoPlayer player)
                                                                         throws TimeoutException

      Runs tasks of the main `Looper` until `ExoPlayer.AudioOffloadListener.onExperimentalOffloadSchedulingEnabledChanged(boolean)` is called or a playback error occurs.

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

      Parameters:
        `player` - The `Player`.
      Returns:
        The new offloadSchedulingEnabled state.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilSleepingForOffload

          public static void runUntilSleepingForOffload​(ExoPlayer player,
                                                        boolean expectedSleepForOffload)
                                                 throws TimeoutException

      Runs tasks of the main `Looper` until `ExoPlayer.AudioOffloadListener.onExperimentalSleepingForOffloadChanged(boolean)` is called or a playback error occurs.

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

      Parameters:
        `player` - The `Player`.
        `expectedSleepForOffload` - The expected sleep of offload state.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilRenderedFirstFrame

          public static void runUntilRenderedFirstFrame​(SimpleExoPlayer player)
                                                 throws TimeoutException

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

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

      Parameters:
        `player` - The `Player`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### playUntilPosition

          public static void playUntilPosition​(ExoPlayer player,
                                               int windowIndex,
                                               long positionMs)
                                        throws TimeoutException

      Calls `Player.play()`, runs tasks of the main `Looper` until the `player` reaches the specified position or a playback error occurs, and then pauses the `player`.

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

      Parameters:
        `player` - The `Player`.
        `windowIndex` - The window.
        `positionMs` - The position within the window, in milliseconds.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### playUntilStartOfWindow

          public static void playUntilStartOfWindow​(ExoPlayer player,
                                                    int windowIndex)
                                             throws TimeoutException

      Calls `Player.play()`, runs tasks of the main `Looper` until the `player` reaches the specified window or a playback error occurs, and then pauses the `player`.

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

      Parameters:
        `player` - The `Player`.
        `windowIndex` - The window.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.

    - #### runUntilPendingCommandsAreFullyHandled

          public static void runUntilPendingCommandsAreFullyHandled​(ExoPlayer player)
                                                             throws TimeoutException

      Runs tasks of the main `Looper` until the player completely handled all previously issued commands on the internal playback thread.
      Parameters:
        `player` - The `Player`.
      Throws:
        `TimeoutException` - If the `default timeout` is exceeded.