MediaSourceTestRunner


@UnstableApi
class MediaSourceTestRunner


A runner for MediaSource tests.

Summary

Constants

const Int
TIMEOUT_MS = 10000

Public constructors

MediaSourceTestRunner(mediaSource: MediaSource!, allocator: Allocator!)

Public functions

Unit

Asserts that the media source reported completed loads via onLoadCompleted for each specified window index and a null period id.

Unit

Asserts that the media source reported completed loads via onLoadCompleted for each specified media period id, and asserts that the associated window index matches the one in the last known timeline returned from prepareSource, assertTimelineChange or assertTimelineChangeBlocking.

Unit

Asserts that the source has not notified its listener of a timeline change since the last call to assertTimelineChangeBlocking or assertTimelineChange (or since the runner was created if neither method has been called).

Unit

Creates and releases all periods (including ad periods) defined in the last timeline to be returned from prepareSource, assertTimelineChange or assertTimelineChangeBlocking.

Timeline!

Asserts that the source has notified its listener of a single timeline change.

Timeline!

Asserts that the source notifies its listener of a single timeline change.

MediaPeriod!

Calls createPeriod with a zero start position on the playback thread, asserting that a non-null MediaPeriod is returned.

MediaPeriod!
createPeriod(periodId: MediaSource.MediaPeriodId!, startPositionUs: Long)

Calls createPeriod on the playback thread, asserting that a non-null MediaPeriod is returned.

CountDownLatch!
preparePeriod(mediaPeriod: MediaPeriod!, positionUs: Long)

Calls prepare on the playback thread and blocks until the method has been called.

Timeline!

Prepares the source on the playback thread, asserting that it provides an initial timeline.

Unit

Releases the runner.

Unit
releasePeriod(mediaPeriod: MediaPeriod!)

Calls releasePeriod on the playback thread.

Unit

Calls releaseSource on the playback thread.

Unit

Runs the provided Runnable on the playback thread, blocking until execution completes.

Constants

TIMEOUT_MS

const val TIMEOUT_MS = 10000: Int

Public constructors

MediaSourceTestRunner

MediaSourceTestRunner(mediaSource: MediaSource!, allocator: Allocator!)
Parameters
mediaSource: MediaSource!

The source under test.

allocator: Allocator!

The allocator to use during the test run.

Public functions

assertCompletedManifestLoads

fun assertCompletedManifestLoads(windowIndices: Array<Int!>!): Unit

Asserts that the media source reported completed loads via onLoadCompleted for each specified window index and a null period id. Also asserts that no other loads with media period id null are reported.

assertCompletedMediaPeriodLoads

fun assertCompletedMediaPeriodLoads(
    mediaPeriodIds: Array<MediaSource.MediaPeriodId!>!
): Unit

Asserts that the media source reported completed loads via onLoadCompleted for each specified media period id, and asserts that the associated window index matches the one in the last known timeline returned from prepareSource, assertTimelineChange or assertTimelineChangeBlocking.

assertNoTimelineChange

@SideEffectFree
fun assertNoTimelineChange(): Unit

Asserts that the source has not notified its listener of a timeline change since the last call to assertTimelineChangeBlocking or assertTimelineChange (or since the runner was created if neither method has been called).

assertPrepareAndReleaseAllPeriods

fun assertPrepareAndReleaseAllPeriods(): Unit

Creates and releases all periods (including ad periods) defined in the last timeline to be returned from prepareSource, assertTimelineChange or assertTimelineChangeBlocking. The windowSequenceNumber is set to the index of the window.

assertTimelineChange

fun assertTimelineChange(): Timeline!

Asserts that the source has notified its listener of a single timeline change.

Returns
Timeline!

The new Timeline.

assertTimelineChangeBlocking

fun assertTimelineChangeBlocking(): Timeline!

Asserts that the source notifies its listener of a single timeline change. If the source has not yet notified its listener, it has up to the timeout passed to the constructor to do so.

Returns
Timeline!

The new Timeline.

createPeriod

fun createPeriod(periodId: MediaSource.MediaPeriodId!): MediaPeriod!

Calls createPeriod with a zero start position on the playback thread, asserting that a non-null MediaPeriod is returned.

Parameters
periodId: MediaSource.MediaPeriodId!

The id of the period to create.

Returns
MediaPeriod!

The created MediaPeriod.

createPeriod

fun createPeriod(periodId: MediaSource.MediaPeriodId!, startPositionUs: Long): MediaPeriod!

Calls createPeriod on the playback thread, asserting that a non-null MediaPeriod is returned.

Parameters
periodId: MediaSource.MediaPeriodId!

The id of the period to create.

startPositionUs: Long

The expected start position, in microseconds.

Returns
MediaPeriod!

The created MediaPeriod.

preparePeriod

fun preparePeriod(mediaPeriod: MediaPeriod!, positionUs: Long): CountDownLatch!

Calls prepare on the playback thread and blocks until the method has been called.

Parameters
mediaPeriod: MediaPeriod!

The MediaPeriod to prepare.

positionUs: Long

The position at which to prepare.

Returns
CountDownLatch!

A CountDownLatch that will be counted down when preparation completes.

prepareSource

fun prepareSource(): Timeline!

Prepares the source on the playback thread, asserting that it provides an initial timeline.

Returns
Timeline!

The initial Timeline.

release

fun release(): Unit

Releases the runner. Should be called when the runner is no longer required.

releasePeriod

fun releasePeriod(mediaPeriod: MediaPeriod!): Unit

Calls releasePeriod on the playback thread.

Parameters
mediaPeriod: MediaPeriod!

The MediaPeriod to release.

releaseSource

fun releaseSource(): Unit

Calls releaseSource on the playback thread.

runOnPlaybackThread

fun runOnPlaybackThread(runnable: Runnable!): Unit

Runs the provided Runnable on the playback thread, blocking until execution completes.

Parameters
runnable: Runnable!

The Runnable to run.