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 providedSimpleExoPlayerinstance reaches a particular state.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidplayUntilPosition(ExoPlayer player, int windowIndex, long positionMs)CallsPlayer.play(), runs tasks of the mainLooperuntil theplayerreaches the specified position or a playback error occurs, and then pauses theplayer.static voidplayUntilStartOfWindow(ExoPlayer player, int windowIndex)CallsPlayer.play(), runs tasks of the mainLooperuntil theplayerreaches the specified window or a playback error occurs, and then pauses theplayer.static ExoPlaybackExceptionrunUntilError(ExoPlayer player)Runs tasks of the mainLooperuntil a player error occurs.static voidrunUntilPendingCommandsAreFullyHandled(ExoPlayer player)Runs tasks of the mainLooperuntil the player completely handled all previously issued commands on the internal playback thread.static voidrunUntilPlaybackState(Player player, int expectedState)Runs tasks of the mainLooperuntilPlayer.getPlaybackState()matches the expected state or a playback error occurs.static voidrunUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady)Runs tasks of the mainLooperuntilPlayer.getPlayWhenReady()matches the expected value or a playback error occurs.static voidrunUntilPositionDiscontinuity(Player player, int expectedReason)Runs tasks of the mainLooperuntilPlayer.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)is called with the specifiedPlayer.DiscontinuityReasonor a playback error occurs.static booleanrunUntilReceiveOffloadSchedulingEnabledNewState(ExoPlayer player)Runs tasks of the mainLooperuntilExoPlayer.AudioOffloadListener.onExperimentalOffloadSchedulingEnabledChanged(boolean)is called or a playback error occurs.static voidrunUntilRenderedFirstFrame(SimpleExoPlayer player)Runs tasks of the mainLooperuntil theVideoListener.onRenderedFirstFrame()callback is called or a playback error occurs.static voidrunUntilSleepingForOffload(ExoPlayer player, boolean expectedSleepForOffload)Runs tasks of the mainLooperuntilExoPlayer.AudioOffloadListener.onExperimentalSleepingForOffloadChanged(boolean)is called or a playback error occurs.static TimelinerunUntilTimelineChanged(Player player)Runs tasks of the mainLooperuntil a timeline change or a playback error occurs.static voidrunUntilTimelineChanged(Player player, Timeline expectedTimeline)Runs tasks of the mainLooperuntilPlayer.getCurrentTimeline()matches the expected timeline or a playback error occurs.
-
-
-
Method Detail
-
runUntilPlaybackState
public static void runUntilPlaybackState(Player player, @State int expectedState) throws TimeoutException
Runs tasks of the mainLooperuntilPlayer.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- ThePlayer.expectedState- The expectedPlayer.State.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilPlayWhenReady
public static void runUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady) throws TimeoutException
Runs tasks of the mainLooperuntilPlayer.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- ThePlayer.expectedPlayWhenReady- The expected value forPlayer.getPlayWhenReady().- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilTimelineChanged
public static void runUntilTimelineChanged(Player player, Timeline expectedTimeline) throws TimeoutException
Runs tasks of the mainLooperuntilPlayer.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- ThePlayer.expectedTimeline- The expectedTimeline.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilTimelineChanged
public static Timeline runUntilTimelineChanged(Player player) throws TimeoutException
Runs tasks of the mainLooperuntil a timeline change or a playback error occurs.If a playback error occurs it will be thrown wrapped in an
IllegalStateException.- Parameters:
player- ThePlayer.- Returns:
- The new
Timeline. - Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilPositionDiscontinuity
public static void runUntilPositionDiscontinuity(Player player, @DiscontinuityReason int expectedReason) throws TimeoutException
Runs tasks of the mainLooperuntilPlayer.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)is called with the specifiedPlayer.DiscontinuityReasonor a playback error occurs.If a playback error occurs it will be thrown wrapped in an
IllegalStateException.- Parameters:
player- ThePlayer.expectedReason- The expectedPlayer.DiscontinuityReason.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilError
public static ExoPlaybackException runUntilError(ExoPlayer player) throws TimeoutException
Runs tasks of the mainLooperuntil a player error occurs.- Parameters:
player- ThePlayer.- Returns:
- The raised
ExoPlaybackException. - Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilReceiveOffloadSchedulingEnabledNewState
public static boolean runUntilReceiveOffloadSchedulingEnabledNewState(ExoPlayer player) throws TimeoutException
Runs tasks of the mainLooperuntilExoPlayer.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- ThePlayer.- Returns:
- The new offloadSchedulingEnabled state.
- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilSleepingForOffload
public static void runUntilSleepingForOffload(ExoPlayer player, boolean expectedSleepForOffload) throws TimeoutException
Runs tasks of the mainLooperuntilExoPlayer.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- ThePlayer.expectedSleepForOffload- The expected sleep of offload state.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilRenderedFirstFrame
public static void runUntilRenderedFirstFrame(SimpleExoPlayer player) throws TimeoutException
Runs tasks of the mainLooperuntil theVideoListener.onRenderedFirstFrame()callback is called or a playback error occurs.If a playback error occurs it will be thrown wrapped in an
IllegalStateException..- Parameters:
player- ThePlayer.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
playUntilPosition
public static void playUntilPosition(ExoPlayer player, int windowIndex, long positionMs) throws TimeoutException
CallsPlayer.play(), runs tasks of the mainLooperuntil theplayerreaches the specified position or a playback error occurs, and then pauses theplayer.If a playback error occurs it will be thrown wrapped in an
IllegalStateException.- Parameters:
player- ThePlayer.windowIndex- The window.positionMs- The position within the window, in milliseconds.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
playUntilStartOfWindow
public static void playUntilStartOfWindow(ExoPlayer player, int windowIndex) throws TimeoutException
CallsPlayer.play(), runs tasks of the mainLooperuntil theplayerreaches the specified window or a playback error occurs, and then pauses theplayer.If a playback error occurs it will be thrown wrapped in an
IllegalStateException.- Parameters:
player- ThePlayer.windowIndex- The window.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilPendingCommandsAreFullyHandled
public static void runUntilPendingCommandsAreFullyHandled(ExoPlayer player) throws TimeoutException
Runs tasks of the mainLooperuntil the player completely handled all previously issued commands on the internal playback thread.- Parameters:
player- ThePlayer.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
-