ExoPlayerTestRunner
@UnstableApi
class ExoPlayerTestRunner : Player.Listener, ActionSchedule.Callback
Helper class to run an ExoPlayer test.
Summary
Nested types |
|---|
|
Builder to set-up an |
Constants |
|
|---|---|
const Format! |
A generic audio |
const Format! |
A generic video |
Public functions |
|
|---|---|
Unit |
Asserts that |
Unit |
assertPlaybackStatesEqual(states: Array<Int!>!)Asserts that the playback states reported by |
Unit |
assertPlayedPeriodIndices(periodIndices: Array<Int!>!)Asserts that the indices of played periods is equal to the provided list of periods. |
Unit |
assertPositionDiscontinuityReasonsEqual(Asserts that the discontinuity reasons reported by |
Unit |
assertTimelineChangeReasonsEqual(reasons: Array<Int!>!)Asserts that the timeline change reasons reported by |
Unit |
assertTimelinesSame(timelines: Array<Timeline!>!)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. |
Unit |
Called when action schedule finished executing all its actions. |
Unit |
onMediaItemTransition(Called when playback transitions to a media item or starts repeating a media item according to the current |
Unit |
onPlaybackStateChanged(@Player.State playbackState: Int)Called when the value returned from |
Unit |
onPlayerError(error: PlaybackException!)Called when an error occurs. |
Unit |
onPositionDiscontinuity(Called when a position discontinuity occurs. |
Unit |
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 functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
AUDIO_FORMAT
const val AUDIO_FORMAT: Format!
A generic audio Format which can be used to set up a FakeMediaSource.
VIDEO_FORMAT
const val VIDEO_FORMAT: Format!
A generic video Format which can be used to set up a FakeMediaSource.
Public functions
assertNoPositionDiscontinuities
fun assertNoPositionDiscontinuities(): Unit
Asserts that onPositionDiscontinuity was not called.
assertPlaybackStatesEqual
fun assertPlaybackStatesEqual(states: Array<Int!>!): Unit
Asserts that the playback states reported by onPlaybackStateChanged are equal to the provided playback states.
assertPlayedPeriodIndices
fun assertPlayedPeriodIndices(periodIndices: Array<Int!>!): Unit
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.
assertPositionDiscontinuityReasonsEqual
fun assertPositionDiscontinuityReasonsEqual(
discontinuityReasons: Array<Int!>!
): Unit
Asserts that the discontinuity reasons reported by onPositionDiscontinuity are equal to the provided values.
assertTimelineChangeReasonsEqual
fun assertTimelineChangeReasonsEqual(reasons: Array<Int!>!): Unit
Asserts that the timeline change reasons reported by onTimelineChanged are equal to the provided timeline change reasons.
assertTimelinesSame
fun assertTimelinesSame(timelines: Array<Timeline!>!): Unit
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.
blockUntilActionScheduleFinished
@CanIgnoreReturnValue
fun blockUntilActionScheduleFinished(timeoutMs: Long): ExoPlayerTestRunner!
Blocks the current thread until the action schedule finished. This does not release the test runner and the test must still call blockUntilEnded.
| Parameters | |
|---|---|
timeoutMs: Long |
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
fun blockUntilEnded(timeoutMs: Long): ExoPlayerTestRunner!
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 | |
|---|---|
timeoutMs: Long |
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
fun onActionScheduleFinished(): Unit
Called when action schedule finished executing all its actions.
onMediaItemTransition
fun onMediaItemTransition(
mediaItem: MediaItem?,
@Player.MediaItemTransitionReason reason: Int
): Unit
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 | |
|---|---|
mediaItem: MediaItem? |
The |
@Player.MediaItemTransitionReason reason: Int |
The reason for the transition. |
onPlaybackStateChanged
fun onPlaybackStateChanged(@Player.State playbackState: Int): Unit
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 playbackState: Int |
The new playback |
onPlayerError
fun onPlayerError(error: PlaybackException!): Unit
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 | |
|---|---|
error: PlaybackException! |
The error. |
onPositionDiscontinuity
fun onPositionDiscontinuity(
oldPosition: Player.PositionInfo!,
newPosition: Player.PositionInfo!,
@Player.DiscontinuityReason reason: Int
): Unit
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 | |
|---|---|
oldPosition: Player.PositionInfo! |
The position before the discontinuity. |
newPosition: Player.PositionInfo! |
The position after the discontinuity. |
@Player.DiscontinuityReason reason: Int |
The |
onTimelineChanged
fun onTimelineChanged(
timeline: Timeline!,
@Player.TimelineChangeReason reason: Int
): Unit
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 reason: Int |
The |
start
@CanIgnoreReturnValue
fun start(): ExoPlayerTestRunner!
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
fun start(doPrepare: Boolean): ExoPlayerTestRunner!
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: Boolean |
Whether the player should be prepared. |
| Returns | |
|---|---|
ExoPlayerTestRunner! |
This test runner. |