MediaSourceTestRunner


@UnstableApi
public class MediaSourceTestRunner


A runner for MediaSource tests.

Summary

Constants

static final int
TIMEOUT_MS = 10000

Public constructors

Creates an instance.

Public methods

void
assertCompletedManifestLoads(Integer[] windowIndices)

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

void
assertCompletedMediaPeriodLoads(
    MediaSource.MediaPeriodId[] mediaPeriodIds
)

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.

void

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).

void

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(MediaSource.MediaPeriodId periodId, long startPositionUs)

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

CountDownLatch
preparePeriod(MediaPeriod mediaPeriod, long positionUs)

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.

void

Releases the runner.

void

Calls releasePeriod on the playback thread.

void

Calls releaseSource on the playback thread.

void

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

Constants

TIMEOUT_MS

public static final int TIMEOUT_MS = 10000

Public constructors

MediaSourceTestRunner

public MediaSourceTestRunner(MediaSource mediaSource)

Creates an instance.

Parameters
MediaSource mediaSource

The source under test.

Public methods

assertCompletedManifestLoads

public void assertCompletedManifestLoads(Integer[] windowIndices)

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

public void assertCompletedMediaPeriodLoads(
    MediaSource.MediaPeriodId[] mediaPeriodIds
)

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
public void assertNoTimelineChange()

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

public void assertPrepareAndReleaseAllPeriods()

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

public Timeline assertTimelineChange()

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

Returns
Timeline

The new Timeline.

assertTimelineChangeBlocking

public Timeline assertTimelineChangeBlocking()

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

public MediaPeriod createPeriod(MediaSource.MediaPeriodId periodId)

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

Parameters
MediaSource.MediaPeriodId periodId

The id of the period to create.

Returns
MediaPeriod

The created MediaPeriod.

createPeriod

public MediaPeriod createPeriod(MediaSource.MediaPeriodId periodId, long startPositionUs)

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

Parameters
MediaSource.MediaPeriodId periodId

The id of the period to create.

long startPositionUs

The expected start position, in microseconds.

Returns
MediaPeriod

The created MediaPeriod.

preparePeriod

public CountDownLatch preparePeriod(MediaPeriod mediaPeriod, long positionUs)

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

Parameters
MediaPeriod mediaPeriod

The MediaPeriod to prepare.

long positionUs

The position at which to prepare.

Returns
CountDownLatch

A CountDownLatch that will be counted down when preparation completes.

prepareSource

public Timeline prepareSource()

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

Returns
Timeline

The initial Timeline.

release

public void release()

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

releasePeriod

public void releasePeriod(MediaPeriod mediaPeriod)

Calls releasePeriod on the playback thread.

Parameters
MediaPeriod mediaPeriod

The MediaPeriod to release.

releaseSource

public void releaseSource()

Calls releaseSource on the playback thread.

runOnPlaybackThread

public void runOnPlaybackThread(Runnable runnable)

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

Parameters
Runnable runnable

The Runnable to run.