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 and then pauses theplayer.static voidplayUntilStartOfWindow(ExoPlayer player, int windowIndex)CallsPlayer.play(), runs tasks of the mainLooperuntil theplayerreaches the specified window and then pauses theplayer.static ExoPlaybackExceptionrunUntilError(Player player)Runs tasks of the mainLooperuntil a player error occurred.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.static voidrunUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady)Runs tasks of the mainLooperuntilPlayer.getPlayWhenReady()matches the expected value.static voidrunUntilPositionDiscontinuity(Player player, int expectedReason)Runs tasks of the mainLooperuntil aPlayer.EventListener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)callback with the specifiedPlayer.DiscontinuityReasonoccurred.static booleanrunUntilReceiveOffloadSchedulingEnabledNewState(ExoPlayer player)Runs tasks of the mainLooperuntil aExoPlayer.AudioOffloadListener.onExperimentalOffloadSchedulingEnabledChanged(boolean)callback occurred.static voidrunUntilRenderedFirstFrame(SimpleExoPlayer player)Runs tasks of the mainLooperuntil theVideoListener.onRenderedFirstFrame()callback has been called.static voidrunUntilSleepingForOffload(ExoPlayer player, boolean expectedSleepForOffload)Runs tasks of the mainLooperuntil aExoPlayer.AudioOffloadListener.onExperimentalSleepingForOffloadChanged(boolean)callback occurred.static TimelinerunUntilTimelineChanged(Player player)Runs tasks of the mainLooperuntil a timeline change occurred.static voidrunUntilTimelineChanged(Player player, Timeline expectedTimeline)Runs tasks of the mainLooperuntilPlayer.getCurrentTimeline()matches the expected timeline.
-
-
-
Method Detail
-
runUntilPlaybackState
public static void runUntilPlaybackState(Player player, @State int expectedState) throws TimeoutException
Runs tasks of the mainLooperuntilPlayer.getPlaybackState()matches the expected state.- 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.- 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.- 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 occurred.- 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 mainLooperuntil aPlayer.EventListener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)callback with the specifiedPlayer.DiscontinuityReasonoccurred.- Parameters:
player- ThePlayer.expectedReason- The expectedPlayer.DiscontinuityReason.- Throws:
TimeoutException- If thedefault timeoutis exceeded.
-
runUntilError
public static ExoPlaybackException runUntilError(Player player) throws TimeoutException
Runs tasks of the mainLooperuntil a player error occurred.- 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 mainLooperuntil aExoPlayer.AudioOffloadListener.onExperimentalOffloadSchedulingEnabledChanged(boolean)callback occurred.- 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 mainLooperuntil aExoPlayer.AudioOffloadListener.onExperimentalSleepingForOffloadChanged(boolean)callback occurred.- 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 has been called.- 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 and then pauses theplayer.- 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 and then pauses theplayer.- 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.
-
-