Class ExoPlayerTestRunner
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.ExoPlayerTestRunner
-
- All Implemented Interfaces:
AudioListener,DeviceListener,MetadataOutput,Player.EventListener,Player.Listener,ActionSchedule.Callback,TextOutput,VideoListener
public final class ExoPlayerTestRunner extends Object implements Player.Listener, ActionSchedule.Callback
Helper class to run an ExoPlayer test.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExoPlayerTestRunner.BuilderBuilder to set-up aExoPlayerTestRunner.
-
Field Summary
Fields Modifier and Type Field Description static FormatAUDIO_FORMATA generic audioFormatwhich can be used to set up aFakeMediaSource.static FormatVIDEO_FORMATA generic videoFormatwhich can be used to set up aFakeMediaSource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertMediaItemsTransitionedSame(MediaItem... mediaItems)Asserts that the media items reported byPlayer.EventListener.onMediaItemTransition(MediaItem, int)are the same as the provided media items.voidassertMediaItemsTransitionReasonsEqual(Integer... reasons)Asserts that the media item transition reasons reported byPlayer.EventListener.onMediaItemTransition(MediaItem, int)are the same as the provided reasons.voidassertNoPositionDiscontinuities()Asserts thatPlayer.EventListener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)was not called.voidassertPlaybackStatesEqual(Integer... states)Asserts that the playback states reported byPlayer.EventListener.onPlaybackStateChanged(int)are equal to the provided playback states.voidassertPlayedPeriodIndices(Integer... periodIndices)Asserts that the indices of played periods is equal to the provided list of periods.voidassertPositionDiscontinuityReasonsEqual(Integer... discontinuityReasons)Asserts that the discontinuity reasons reported byPlayer.EventListener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)are equal to the provided values.voidassertTimelineChangeReasonsEqual(Integer... reasons)Asserts that the timeline change reasons reported byPlayer.EventListener.onTimelineChanged(Timeline, int)are equal to the provided timeline change reasons.voidassertTimelinesSame(Timeline... timelines)Asserts that the timelines reported byPlayer.EventListener.onTimelineChanged(Timeline, int)are the same to the provided timelines.voidassertTrackGroupsEqual(TrackGroupArray trackGroupArray)Asserts that the last track group array reported byPlayer.EventListener.onTracksChanged(TrackGroupArray, TrackSelectionArray)is equal to the provided track group array.ExoPlayerTestRunnerblockUntilActionScheduleFinished(long timeoutMs)Blocks the current thread until the action schedule finished.ExoPlayerTestRunnerblockUntilEnded(long timeoutMs)Blocks the current thread until the test runner finishes.voidonActionScheduleFinished()Called when action schedule finished executing all its actions.voidonMediaItemTransition(MediaItem mediaItem, int reason)Called when playback transitions to a media item or starts repeating a media item according to the currentrepeat mode.voidonPlaybackStateChanged(int playbackState)Called when the value returned fromPlayer.getPlaybackState()changes.voidonPlayerError(ExoPlaybackException error)Called when an error occurs.voidonPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason)Called when a position discontinuity occurs.voidonTimelineChanged(Timeline timeline, int reason)Called when the timeline has been refreshed.voidonTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections)Called when the available or selected tracks change.ExoPlayerTestRunnerstart()Starts the test runner on its own thread.ExoPlayerTestRunnerstart(boolean doPrepare)Starts the test runner on its own thread.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.audio.AudioListener
onAudioAttributesChanged, onAudioSessionIdChanged, onSkipSilenceEnabledChanged, onVolumeChanged
-
Methods inherited from interface com.google.android.exoplayer2.device.DeviceListener
onDeviceInfoChanged, onDeviceVolumeChanged
-
Methods inherited from interface com.google.android.exoplayer2.Player.EventListener
onAvailableCommandsChanged, onEvents, onIsLoadingChanged, onIsPlayingChanged, onLoadingChanged, onMediaMetadataChanged, onPlaybackParametersChanged, onPlaybackSuppressionReasonChanged, onPlayerStateChanged, onPlayWhenReadyChanged, onPositionDiscontinuity, onRepeatModeChanged, onSeekProcessed, onShuffleModeEnabledChanged, onStaticMetadataChanged, onTimelineChanged
-
Methods inherited from interface com.google.android.exoplayer2.Player.Listener
onCues, onMetadata
-
Methods inherited from interface com.google.android.exoplayer2.video.VideoListener
onRenderedFirstFrame, onSurfaceSizeChanged, onVideoSizeChanged, onVideoSizeChanged
-
-
-
-
Field Detail
-
VIDEO_FORMAT
public static final Format VIDEO_FORMAT
A generic videoFormatwhich can be used to set up aFakeMediaSource.
-
AUDIO_FORMAT
public static final Format AUDIO_FORMAT
A generic audioFormatwhich can be used to set up aFakeMediaSource.
-
-
Method Detail
-
start
public ExoPlayerTestRunner start()
Starts the test runner on its own thread. This will trigger the creation of the player, the listener registration, the start of the action schedule, the initial set of media items and the preparation of the player.- Returns:
- This test runner.
-
start
public ExoPlayerTestRunner start(boolean doPrepare)
Starts the test runner on its own thread. This will trigger the creation of the player, the listener registration, the start of the action schedule and the initial set of media items.- Parameters:
doPrepare- Whether the player should be prepared.- Returns:
- This test runner.
-
blockUntilEnded
public ExoPlayerTestRunner blockUntilEnded(long timeoutMs) throws Exception
Blocks the current thread until the test runner finishes. A test is deemed to be finished when the playback state transitioned toPlayer.STATE_ENDEDorPlayer.STATE_IDLEfor the specified number of times. The test also finishes when anExoPlaybackExceptionis thrown.- Parameters:
timeoutMs- The maximum time to wait for the test runner to finish. If this time elapsed the method will throw aTimeoutException.- Returns:
- This test runner.
- Throws:
Exception- If any exception occurred during playback, release, or due to a timeout.
-
blockUntilActionScheduleFinished
public ExoPlayerTestRunner blockUntilActionScheduleFinished(long timeoutMs) throws TimeoutException, InterruptedException
Blocks the current thread until the action schedule finished. This does not release the test runner and the test must still callblockUntilEnded(long).- Parameters:
timeoutMs- The maximum time to wait for the action schedule to finish.- Returns:
- This test runner.
- Throws:
TimeoutException- If the action schedule did not finish within the specified timeout.InterruptedException- If the test thread gets interrupted while waiting.
-
assertTimelinesSame
public void assertTimelinesSame(Timeline... timelines)
Asserts that the timelines reported byPlayer.EventListener.onTimelineChanged(Timeline, int)are the same to the provided timelines. This assert differs from testing equality by not comparing period ids which may be different due to id mapping of child source period ids.- Parameters:
timelines- A list of expectedTimelines.
-
assertTimelineChangeReasonsEqual
public void assertTimelineChangeReasonsEqual(Integer... reasons)
Asserts that the timeline change reasons reported byPlayer.EventListener.onTimelineChanged(Timeline, int)are equal to the provided timeline change reasons.
-
assertMediaItemsTransitionedSame
public void assertMediaItemsTransitionedSame(MediaItem... mediaItems)
Asserts that the media items reported byPlayer.EventListener.onMediaItemTransition(MediaItem, int)are the same as the provided media items.- Parameters:
mediaItems- A list of expectedmedia items.
-
assertMediaItemsTransitionReasonsEqual
public void assertMediaItemsTransitionReasonsEqual(Integer... reasons)
Asserts that the media item transition reasons reported byPlayer.EventListener.onMediaItemTransition(MediaItem, int)are the same as the provided reasons.- Parameters:
reasons- A list of expected transition reasons.
-
assertPlaybackStatesEqual
public void assertPlaybackStatesEqual(Integer... states)
Asserts that the playback states reported byPlayer.EventListener.onPlaybackStateChanged(int)are equal to the provided playback states.
-
assertTrackGroupsEqual
public void assertTrackGroupsEqual(TrackGroupArray trackGroupArray)
Asserts that the last track group array reported byPlayer.EventListener.onTracksChanged(TrackGroupArray, TrackSelectionArray)is equal to the provided track group array.- Parameters:
trackGroupArray- The expectedTrackGroupArray.
-
assertNoPositionDiscontinuities
public void assertNoPositionDiscontinuities()
Asserts thatPlayer.EventListener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)was not called.
-
assertPositionDiscontinuityReasonsEqual
public void assertPositionDiscontinuityReasonsEqual(Integer... discontinuityReasons)
Asserts that the discontinuity reasons reported byPlayer.EventListener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)are equal to the provided values.- Parameters:
discontinuityReasons- The expected discontinuity reasons.
-
assertPlayedPeriodIndices
public void assertPlayedPeriodIndices(Integer... periodIndices)
Asserts that the indices of played periods is equal to the provided list of periods. A period is considered to be played if it was the current period after a position discontinuity or a media source preparation. When the same period is repeated automatically due to enabled repeat modes, it is reported twice. Seeks within the current period are not reported.- Parameters:
periodIndices- A list of expected period indices.
-
onTimelineChanged
public void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason)
Description copied from interface:Player.EventListenerCalled when the timeline has been refreshed.Note that the current window or period index may change as a result of a timeline change. If playback can't continue smoothly because of this timeline change, a separate
Player.EventListener.onPositionDiscontinuity(PositionInfo, PositionInfo, int)callback will be triggered.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onTimelineChangedin interfacePlayer.EventListener- Parameters:
timeline- The latest timeline. Never null, but may be empty.reason- ThePlayer.TimelineChangeReasonresponsible for this timeline change.
-
onMediaItemTransition
public void onMediaItemTransition(@Nullable MediaItem mediaItem, @MediaItemTransitionReason int reason)Description copied from interface:Player.EventListenerCalled when playback transitions to a media item or starts repeating a media item according to the currentrepeat mode.Note that this callback is also called when the playlist becomes non-empty or empty as a consequence of a playlist change.
Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onMediaItemTransitionin interfacePlayer.EventListener- Parameters:
mediaItem- TheMediaItem. May be null if the playlist becomes empty.reason- The reason for the transition.
-
onTracksChanged
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections)
Description copied from interface:Player.EventListenerCalled when the available or selected tracks change.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onTracksChangedin interfacePlayer.EventListener- Parameters:
trackGroups- The available tracks. Never null, but may be of length zero.trackSelections- The selected tracks. Never null, but may contain null elements. A concrete implementation may include null elements if it has a fixed number of renderer components, wishes to report a TrackSelection for each of them, and has one or more renderer components that is not assigned any selected tracks.
-
onPlaybackStateChanged
public void onPlaybackStateChanged(@State int playbackState)
Description copied from interface:Player.EventListenerCalled when the value returned fromPlayer.getPlaybackState()changes.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPlaybackStateChangedin interfacePlayer.EventListener- Parameters:
playbackState- The new playbackstate.
-
onPlayerError
public void onPlayerError(ExoPlaybackException error)
Description copied from interface:Player.EventListenerCalled when an error occurs. The playback state will transition toPlayer.STATE_IDLEimmediately after this method is called. The player instance can still be used, andPlayer.release()must still be called on the player should it no longer be required.Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPlayerErrorin interfacePlayer.EventListener- Parameters:
error- The error.
-
onPositionDiscontinuity
public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, @DiscontinuityReason int reason)
Description copied from interface:Player.EventListenerCalled when a position discontinuity occurs.A position discontinuity occurs when the playing period changes, the playback position jumps within the period currently being played, or when the playing period has been skipped or removed.
Player.EventListener.onEvents(Player, Events)will also be called to report this event along with other events that happen in the sameLoopermessage queue iteration.- Specified by:
onPositionDiscontinuityin interfacePlayer.EventListener- Parameters:
oldPosition- The position before the discontinuity.newPosition- The position after the discontinuity.reason- ThePlayer.DiscontinuityReasonresponsible for the discontinuity.
-
onActionScheduleFinished
public void onActionScheduleFinished()
Description copied from interface:ActionSchedule.CallbackCalled when action schedule finished executing all its actions.- Specified by:
onActionScheduleFinishedin interfaceActionSchedule.Callback
-
-