Back to Exoplayer

ExoPlayerTestRunner (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/testutil/ExoPlayerTestRunner.html

latest20.6 KB
Original Source

Package com.google.android.exoplayer2.testutil

Class ExoPlayerTestRunner

  • java.lang.Object

    • com.google.android.exoplayer2.testutil.ExoPlayerTestRunner
  • All Implemented Interfaces:Player.Listener, ActionSchedule.Callback


public final classExoPlayerTestRunnerextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[Player.Listener](../Player.Listener.html "interface in com.google.android.exoplayer2"),[ActionSchedule.Callback](ActionSchedule.Callback.html "interface in com.google.android.exoplayer2.testutil")

Helper class to run an ExoPlayer test.

Nested Class Summary

Nested Classes | Modifier and Type | Class | Description | | --- | --- | --- | | static class | ExoPlayerTestRunner.Builder | Builder to set-up an ExoPlayerTestRunner. |

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | static Format | AUDIO_FORMAT | A generic audio Format which can be used to set up a FakeMediaSource. | | static Format | VIDEO_FORMAT | A generic video Format which can be used to set up a FakeMediaSource. |

Method Summary

All Methods Instance Methods Concrete Methods | Modifier and Type | Method | Description | | --- | --- | --- | | void | assertNoPositionDiscontinuities() | Asserts that Player.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int) was not called. | | void | assertPlaybackStatesEqual​(Integer... states) | Asserts that the playback states reported by Player.Listener.onPlaybackStateChanged(int) are equal to the provided playback states. | | void | assertPlayedPeriodIndices​(Integer... periodIndices) | Asserts that the indices of played periods is equal to the provided list of periods. | | void | assertPositionDiscontinuityReasonsEqual​(Integer... discontinuityReasons) | Asserts that the discontinuity reasons reported by Player.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int) are equal to the provided values. | | void | assertTimelineChangeReasonsEqual​(Integer... reasons) | Asserts that the timeline change reasons reported by Player.Listener.onTimelineChanged(Timeline, int) are equal to the provided timeline change reasons. | | void | assertTimelinesSame​(Timeline... timelines) | Asserts that the timelines reported by Player.Listener.onTimelineChanged(Timeline, int) are the same to the provided timelines. | | ExoPlayerTestRunner | blockUntilActionScheduleFinished​(long timeoutMs) | Blocks the current thread until the action schedule finished. | | ExoPlayerTestRunner | blockUntilEnded​(long timeoutMs) | Blocks the current thread until the test runner finishes. | | void | onActionScheduleFinished() | Called when action schedule finished executing all its actions. | | void | onMediaItemTransition​(MediaItem mediaItem, @com.google.android.exoplayer2.Player.MediaItemTransitionReason int reason) | Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode. | | void | onPlaybackStateChanged​(@com.google.android.exoplayer2.Player.State int playbackState) | Called when the value returned from Player.getPlaybackState() changes. | | void | onPlayerError​(PlaybackException error) | Called when an error occurs. | | void | onPositionDiscontinuity​(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, @com.google.android.exoplayer2.Player.DiscontinuityReason int reason) | Called when a position discontinuity occurs. | | void | onTimelineChanged​(Timeline timeline, @com.google.android.exoplayer2.Player.TimelineChangeReason int reason) | Called when the value of Player.getCurrentTimeline() changes. | | ExoPlayerTestRunner | start() | Starts the test runner on its own thread. | | ExoPlayerTestRunner | start​(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.Player.Listener

onAudioAttributesChanged, onAudioSessionIdChanged, onAvailableCommandsChanged, onCues, onCues, onDeviceInfoChanged, onDeviceVolumeChanged, onEvents, onIsLoadingChanged, onIsPlayingChanged, onLoadingChanged, onMaxSeekToPreviousPositionChanged, onMediaMetadataChanged, onMetadata, onPlaybackParametersChanged, onPlaybackSuppressionReasonChanged, onPlayerErrorChanged, onPlayerStateChanged, onPlaylistMetadataChanged, onPlayWhenReadyChanged, onPositionDiscontinuity, onRenderedFirstFrame, onRepeatModeChanged, onSeekBackIncrementChanged, onSeekForwardIncrementChanged, onShuffleModeEnabledChanged, onSkipSilenceEnabledChanged, onSurfaceSizeChanged, onTracksChanged, onTrackSelectionParametersChanged, onVideoSizeChanged, onVolumeChanged

Field Detail

- 

VIDEO_FORMAT

public static final[Format](../Format.html "class in com.google.android.exoplayer2")VIDEO_FORMAT

A generic video Format which can be used to set up a FakeMediaSource.

- 

AUDIO_FORMAT

public static final[Format](../Format.html "class in com.google.android.exoplayer2")AUDIO_FORMAT

A generic audio Format which can be used to set up a FakeMediaSource.

Method Detail

- 

start

@CanIgnoreReturnValue
public[ExoPlayerTestRunner](ExoPlayerTestRunner.html "class in com.google.android.exoplayer2.testutil")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

@CanIgnoreReturnValue
public[ExoPlayerTestRunner](ExoPlayerTestRunner.html "class in com.google.android.exoplayer2.testutil")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

@CanIgnoreReturnValue
public[ExoPlayerTestRunner](ExoPlayerTestRunner.html "class in com.google.android.exoplayer2.testutil")blockUntilEnded​(long timeoutMs)
                                    throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Blocks the current thread until the test runner finishes. A test is deemed to be finished when the playback state transitioned to Player.STATE_ENDED or Player.STATE_IDLE for the specified number of times. The test also finishes when an ExoPlaybackException is thrown. Parameters:timeoutMs - The maximum time to wait for the test runner to finish. If this time elapsed the method will throw a TimeoutException.Returns:This test runner.Throws:Exception - If any exception occurred during playback, release, or due to a timeout.

- 

blockUntilActionScheduleFinished

@CanIgnoreReturnValue
public[ExoPlayerTestRunner](ExoPlayerTestRunner.html "class in com.google.android.exoplayer2.testutil")blockUntilActionScheduleFinished​(long timeoutMs)
                                                     throws[TimeoutException](https://developer.android.com/reference/java/util/concurrent/TimeoutException.html "class or interface in java.util.concurrent"),[InterruptedException](https://developer.android.com/reference/java/lang/InterruptedException.html "class or interface in java.lang")

Blocks the current thread until the action schedule finished. This does not release the test runner and the test must still call blockUntilEnded(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](../Timeline.html "class in com.google.android.exoplayer2")... timelines)

Asserts that the timelines reported by Player.Listener.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 expected Timelines.

- 

assertTimelineChangeReasonsEqual

public void assertTimelineChangeReasonsEqual​([Integer](https://developer.android.com/reference/java/lang/Integer.html "class or interface in java.lang")... reasons)

Asserts that the timeline change reasons reported by Player.Listener.onTimelineChanged(Timeline, int) are equal to the provided timeline change reasons.

- 

assertPlaybackStatesEqual

public void assertPlaybackStatesEqual​([Integer](https://developer.android.com/reference/java/lang/Integer.html "class or interface in java.lang")... states)

Asserts that the playback states reported by Player.Listener.onPlaybackStateChanged(int) are equal to the provided playback states.

- 

assertNoPositionDiscontinuities

public void assertNoPositionDiscontinuities()

Asserts that Player.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int) was not called.

- 

assertPositionDiscontinuityReasonsEqual

public void assertPositionDiscontinuityReasonsEqual​([Integer](https://developer.android.com/reference/java/lang/Integer.html "class or interface in java.lang")... discontinuityReasons)

Asserts that the discontinuity reasons reported by Player.Listener.onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int) are equal to the provided values. Parameters:discontinuityReasons - The expected discontinuity reasons.

- 

assertPlayedPeriodIndices

public void assertPlayedPeriodIndices​([Integer](https://developer.android.com/reference/java/lang/Integer.html "class or interface in java.lang")... 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.html "class in com.google.android.exoplayer2")timeline,[@TimelineChangeReason](../Player.TimelineChangeReason.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.TimelineChangeReason int reason)

Description copied from interface: Player.Listener

Called when the value of Player.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 Player.Listener.onPositionDiscontinuity(PositionInfo, PositionInfo, int) callback will be triggered.

Player.Listener.onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper message queue iteration.

Specified by:onTimelineChanged in interface Player.ListenerParameters:timeline - The latest timeline. Never null, but may be empty.reason - The Player.TimelineChangeReason responsible for this timeline change.

- 

onMediaItemTransition

public void onMediaItemTransition​(@Nullable[MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")mediaItem,[@MediaItemTransitionReason](../Player.MediaItemTransitionReason.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.MediaItemTransitionReason int reason)

Description copied from interface: Player.Listener

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 Player.getCurrentTimeline() becomes non-empty or empty.

Player.Listener.onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper message queue iteration.

Specified by:onMediaItemTransition in interface Player.ListenerParameters:mediaItem - The MediaItem. May be null if the playlist becomes empty.reason - The reason for the transition.

- 

onPlaybackStateChanged

public void onPlaybackStateChanged​([@State](../Player.State.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.State int playbackState)

Description copied from interface: Player.Listener

Called when the value returned from Player.getPlaybackState() changes.

Player.Listener.onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper message queue iteration.

Specified by:onPlaybackStateChanged in interface Player.ListenerParameters:playbackState - The new playback Player.State.

- 

onPlayerError

public void onPlayerError​([PlaybackException](../PlaybackException.html "class in com.google.android.exoplayer2")error)

Description copied from interface: Player.Listener

Called when an error occurs. The playback state will transition to Player.STATE_IDLE immediately after this method is called. The player instance can still be used, and Player.release() must still be called on the player should it no longer be required.

Player.Listener.onEvents(Player, Events) 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.

Specified by:onPlayerError in interface Player.ListenerParameters:error - The error.

- 

onPositionDiscontinuity

public void onPositionDiscontinuity​([Player.PositionInfo](../Player.PositionInfo.html "class in com.google.android.exoplayer2")oldPosition,[Player.PositionInfo](../Player.PositionInfo.html "class in com.google.android.exoplayer2")newPosition,[@DiscontinuityReason](../Player.DiscontinuityReason.html "annotation in com.google.android.exoplayer2")@com.google.android.exoplayer2.Player.DiscontinuityReason int reason)

Description copied from interface: Player.Listener

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.

Player.Listener.onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper message queue iteration.

Specified by:onPositionDiscontinuity in interface Player.ListenerParameters:oldPosition - The position before the discontinuity.newPosition - The position after the discontinuity.reason - The Player.DiscontinuityReason responsible for the discontinuity.

- 

onActionScheduleFinished

public void onActionScheduleFinished()

Description copied from interface: ActionSchedule.Callback

Called when action schedule finished executing all its actions. Specified by:onActionScheduleFinished in interface ActionSchedule.Callback