ExoPlayerTestRunner
@UnstableApi
public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedule.Callback
Helper class to run an ExoPlayer test.
Summary
Nested types |
|---|
public final class ExoPlayerTestRunner.BuilderBuilder to set-up an |
Constants |
|
|---|---|
static final Format |
A generic audio |
static final Format |
A generic video |
Public methods |
|
|---|---|
void |
Asserts that |
void |
assertPlaybackStatesEqual(Integer[] states)Asserts that the playback states reported by |
void |
assertPlayedPeriodIndices(Integer[] periodIndices)Asserts that the indices of played periods is equal to the provided list of periods. |
void |
assertPositionDiscontinuityReasonsEqual(Asserts that the discontinuity reasons reported by |
void |
assertTimelineChangeReasonsEqual(Integer[] reasons)Asserts that the timeline change reasons reported by |
void |
assertTimelinesSame(Timeline[] timelines)Asserts that the timelines reported by |
ExoPlayerTestRunner |
@CanIgnoreReturnValueBlocks the current thread until the action schedule finished. |
ExoPlayerTestRunner |
@CanIgnoreReturnValueBlocks the current thread until the test runner finishes. |
void |
Called when action schedule finished executing all its actions. |
void |
onMediaItemTransition(Called when playback transitions to a media item or starts repeating a media item according to the current |
void |
onPlaybackStateChanged(@Player.State int playbackState)Called when the value returned from |
void |
onPlayerError(PlaybackException error)Called when an error occurs. |
void |
onPositionDiscontinuity(Called when a position discontinuity occurs. |
void |
onTimelineChanged(Called when the value of |
ExoPlayerTestRunner |
Starts the test runner on its own thread. |
ExoPlayerTestRunner |
@CanIgnoreReturnValueStarts the test runner on its own thread. |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
AUDIO_FORMAT
public static final Format AUDIO_FORMAT
A generic audio Format which can be used to set up a FakeMediaSource.
VIDEO_FORMAT
public static final Format VIDEO_FORMAT
A generic video Format which can be used to set up a FakeMediaSource.
Public methods
assertNoPositionDiscontinuities
public void assertNoPositionDiscontinuities()
Asserts that onPositionDiscontinuity was not called.
assertPlaybackStatesEqual
public void assertPlaybackStatesEqual(Integer[] states)
Asserts that the playback states reported by onPlaybackStateChanged are equal to the provided playback states.
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 | |
|---|---|
Integer[] periodIndices |
A list of expected period indices. |
assertPositionDiscontinuityReasonsEqual
public void assertPositionDiscontinuityReasonsEqual(
Integer[] discontinuityReasons
)
Asserts that the discontinuity reasons reported by onPositionDiscontinuity are equal to the provided values.
| Parameters | |
|---|---|
Integer[] discontinuityReasons |
The expected discontinuity reasons. |
assertTimelineChangeReasonsEqual
public void assertTimelineChangeReasonsEqual(Integer[] reasons)
Asserts that the timeline change reasons reported by onTimelineChanged are equal to the provided timeline change reasons.
assertTimelinesSame
public void assertTimelinesSame(Timeline[] timelines)
Asserts that the timelines reported by onTimelineChanged 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 | |
|---|---|
Timeline[] timelines |
A list of expected |
blockUntilActionScheduleFinished
@CanIgnoreReturnValue
public ExoPlayerTestRunner blockUntilActionScheduleFinished(long timeoutMs)
Blocks the current thread until the action schedule finished. This does not release the test runner and the test must still call blockUntilEnded.
| Parameters | |
|---|---|
long timeoutMs |
The maximum time to wait for the action schedule to finish. |
| Returns | |
|---|---|
ExoPlayerTestRunner |
This test runner. |
| Throws | |
|---|---|
java.util.concurrent.TimeoutException |
If the action schedule did not finish within the specified timeout. |
java.lang.InterruptedException |
If the test thread gets interrupted while waiting. |
blockUntilEnded
@CanIgnoreReturnValue
public ExoPlayerTestRunner blockUntilEnded(long timeoutMs)
Blocks the current thread until the test runner finishes. A test is deemed to be finished when the playback state transitioned to STATE_ENDED or STATE_IDLE for the specified number of times. The test also finishes when an ExoPlaybackException is thrown.
| Parameters | |
|---|---|
long timeoutMs |
The maximum time to wait for the test runner to finish. If this time elapsed the method will throw a |
| Returns | |
|---|---|
ExoPlayerTestRunner |
This test runner. |
| Throws | |
|---|---|
java.lang.Exception |
If any exception occurred during playback, release, or due to a timeout. |
onActionScheduleFinished
public void onActionScheduleFinished()
Called when action schedule finished executing all its actions.
onMediaItemTransition
public void onMediaItemTransition(
@Nullable MediaItem mediaItem,
@Player.MediaItemTransitionReason int reason
)
Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode.
Note that this callback is also called when the value of getCurrentTimeline becomes non-empty or empty.
onEvents will also be called to report this event along with other events that happen in the same Looper message queue iteration.
| Parameters | |
|---|---|
@Nullable MediaItem mediaItem |
The |
@Player.MediaItemTransitionReason int reason |
The reason for the transition. |
onPlaybackStateChanged
public void onPlaybackStateChanged(@Player.State int playbackState)
Called when the value returned from getPlaybackState changes.
onEvents will also be called to report this event along with other events that happen in the same Looper message queue iteration.
| Parameters | |
|---|---|
@Player.State int playbackState |
The new playback |
onPlayerError
public void onPlayerError(PlaybackException error)
Called when an error occurs. The playback state will transition to STATE_IDLE immediately after this method is called. The player instance can still be used, and release must still be called on the player should it no longer be required.
onEvents will also be called to report this event along with other events that happen in the same Looper message queue iteration.
Implementations of Player may pass an instance of a subclass of PlaybackException to this method in order to include more information about the error.
| Parameters | |
|---|---|
PlaybackException error |
The error. |
onPositionDiscontinuity
public void onPositionDiscontinuity(
Player.PositionInfo oldPosition,
Player.PositionInfo newPosition,
@Player.DiscontinuityReason int reason
)
Called 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.
onEvents will also be called to report this event along with other events that happen in the same Looper message queue iteration.
| Parameters | |
|---|---|
Player.PositionInfo oldPosition |
The position before the discontinuity. |
Player.PositionInfo newPosition |
The position after the discontinuity. |
@Player.DiscontinuityReason int reason |
The |
onTimelineChanged
public void onTimelineChanged(
Timeline timeline,
@Player.TimelineChangeReason int reason
)
Called when the value of getCurrentTimeline changes.
Note that the current MediaItem or playback position may change as a result of a timeline change. If playback can't continue smoothly because of this timeline change, a separate onPositionDiscontinuity callback will be triggered.
onEvents will also be called to report this event along with other events that happen in the same Looper message queue iteration.
| Parameters | |
|---|---|
Timeline timeline |
The latest timeline. Never null, but may be empty. |
@Player.TimelineChangeReason int reason |
The |
start
@CanIgnoreReturnValue
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 | |
|---|---|
ExoPlayerTestRunner |
This test runner. |
start
@CanIgnoreReturnValue
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 | |
|---|---|
boolean doPrepare |
Whether the player should be prepared. |
| Returns | |
|---|---|
ExoPlayerTestRunner |
This test runner. |