@UnstableApi
public abstract class ExoHostedTest implements HostActivity.HostedTest


A HostedTest for ExoPlayer playback tests.

Summary

Constants

static final long
static final long
static final long

Protected fields

final String

Public constructors

ExoHostedTest(@Size(max = 23) String tag, boolean fullPlaybackNoSeeking)
ExoHostedTest(
    @Size(max = 23) String tag,
    long expectedPlayingTimeMs,
    boolean failOnPlayerError
)

Public methods

final boolean
blockUntilStopped(long timeoutMs)

Called on the main thread to block until the test has stopped or forceStop is called.

final boolean

Called on the main thread to force stop the test (if it is not stopped already).

final void

Called on the test thread after the test has finished and been stopped.

final void
onStart(
    HostActivity host,
    Surface surface,
    FrameLayout overlayFrameLayout
)

Called on the main thread when the test is started.

final void

Sets a schedule to be applied during the test.

Protected methods

void
assertPassed(
    DecoderCounters audioCounters,
    DecoderCounters videoCounters
)
DrmSessionManager
ExoPlayer
buildExoPlayer(
    HostActivity host,
    Surface surface,
    MappingTrackSelector trackSelector
)
abstract MediaSource
buildSource(
    HostActivity host,
    DrmSessionManager drmSessionManager,
    FrameLayout overlayFrameLayout
)
DefaultTrackSelector
void
logMetrics(
    DecoderCounters audioCounters,
    DecoderCounters videoCounters
)
void

Constants

EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS

public static final long EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS = -2

EXPECTED_PLAYING_TIME_UNSET

public static final long EXPECTED_PLAYING_TIME_UNSET = -1

MAX_PLAYING_TIME_DISCREPANCY_MS

public static final long MAX_PLAYING_TIME_DISCREPANCY_MS = 5000

Protected fields

tag

protected final String tag

Public constructors

ExoHostedTest

public ExoHostedTest(@Size(max = 23) String tag, boolean fullPlaybackNoSeeking)
Parameters
@Size(max = 23) String tag

A tag to use for logging.

boolean fullPlaybackNoSeeking

Whether the test will play the target media in full without seeking. If set to true, the test will assert that the total time spent playing the media was within MAX_PLAYING_TIME_DISCREPANCY_MS of the media duration. If set to false, the test will not assert an expected playing time.

ExoHostedTest

public ExoHostedTest(
    @Size(max = 23) String tag,
    long expectedPlayingTimeMs,
    boolean failOnPlayerError
)
Parameters
@Size(max = 23) String tag

A tag to use for logging.

long expectedPlayingTimeMs

The expected playing time. If set to a non-negative value, the test will assert that the total time spent playing the media was within MAX_PLAYING_TIME_DISCREPANCY_MS of the specified value. EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS should be passed to assert that the expected playing time equals the duration of the media being played. Else EXPECTED_PLAYING_TIME_UNSET should be passed to indicate that the test should not assert an expected playing time.

boolean failOnPlayerError

Whether a player error should be considered a test failure.

Public methods

blockUntilStopped

public final boolean blockUntilStopped(long timeoutMs)

Called on the main thread to block until the test has stopped or forceStop is called.

Parameters
long timeoutMs

The maximum time to block in milliseconds.

Returns
boolean

Whether the test has stopped successful.

forceStop

public final boolean forceStop()

Called on the main thread to force stop the test (if it is not stopped already).

Returns
boolean

Whether the test was forced stopped.

onFinished

public final void onFinished()

Called on the test thread after the test has finished and been stopped.

Implementations may use this method to assert that test criteria were met.

onStart

public final void onStart(
    HostActivity host,
    Surface surface,
    FrameLayout overlayFrameLayout
)

Called on the main thread when the test is started.

The test will not be started until the HostActivity has been resumed and its Surface has been created.

Parameters
HostActivity host

The HostActivity in which the test is being run.

Surface surface

The Surface.

FrameLayout overlayFrameLayout

A FrameLayout that is on top of the surface.

setSchedule

public final void setSchedule(ActionSchedule schedule)

Sets a schedule to be applied during the test.

Parameters
ActionSchedule schedule

The schedule.

Protected methods

assertPassed

protected void assertPassed(
    DecoderCounters audioCounters,
    DecoderCounters videoCounters
)

buildDrmSessionManager

protected DrmSessionManager buildDrmSessionManager()

buildExoPlayer

protected ExoPlayer buildExoPlayer(
    HostActivity host,
    Surface surface,
    MappingTrackSelector trackSelector
)

buildSource

protected abstract MediaSource buildSource(
    HostActivity host,
    DrmSessionManager drmSessionManager,
    FrameLayout overlayFrameLayout
)

buildTrackSelector

protected DefaultTrackSelector buildTrackSelector(HostActivity host)

logMetrics

protected void logMetrics(
    DecoderCounters audioCounters,
    DecoderCounters videoCounters
)

onPlayerErrorInternal

protected void onPlayerErrorInternal(ExoPlaybackException error)