# ExoHostedTest

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/ExoHostedTest.java+class:androidx.media3.test.utils.ExoHostedTest)

*** ** * ** ***


```
@UnstableApi
public abstract class ExoHostedTest implements HostActivity.HostedTest
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/test/utils/HostActivity.HostedTest` for `https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer` playback tests.

## Summary

| ### Constants |
|---|---|
| `static final long` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS() = -2` |
| `static final long` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#EXPECTED_PLAYING_TIME_UNSET() = -1` |
| `static final long` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#MAX_PLAYING_TIME_DISCREPANCY_MS() = 5000` |

| ### Protected fields |
|---|---|
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#tag()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#ExoHostedTest(java.lang.String,boolean)(@https://developer.android.com/reference/androidx/annotation/Size(max = 23) https://developer.android.com/reference/java/lang/String.html tag, boolean fullPlaybackNoSeeking)` |
| `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#ExoHostedTest(java.lang.String,long,boolean)( @https://developer.android.com/reference/androidx/annotation/Size(max = 23) https://developer.android.com/reference/java/lang/String.html tag, long expectedPlayingTimeMs, boolean failOnPlayerError )` |

| ### Public methods |
|---|---|
| `final boolean` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#blockUntilStopped(long)(long timeoutMs)` Called on the main thread to block until the test has stopped or `https://developer.android.com/reference/androidx/media3/test/utils/HostActivity.HostedTest#forceStop()` is called. |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#forceStop()()` Called on the main thread to force stop the test (if it is not stopped already). |
| `final void` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#onFinished()()` Called on the test thread after the test has finished and been stopped. |
| `final void` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#onStart(androidx.media3.test.utils.HostActivity,android.view.Surface,android.widget.FrameLayout)( https://developer.android.com/reference/androidx/media3/test/utils/HostActivity host, https://developer.android.com/reference/android/view/Surface.html surface, https://developer.android.com/reference/android/widget/FrameLayout.html overlayFrameLayout )` Called on the main thread when the test is started. |
| `final void` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#setSchedule(androidx.media3.test.utils.ActionSchedule)(https://developer.android.com/reference/androidx/media3/test/utils/ActionSchedule schedule)` Sets a schedule to be applied during the test. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#assertPassed(androidx.media3.exoplayer.DecoderCounters,androidx.media3.exoplayer.DecoderCounters)( https://developer.android.com/reference/androidx/media3/exoplayer/DecoderCounters audioCounters, https://developer.android.com/reference/androidx/media3/exoplayer/DecoderCounters videoCounters )` |
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#buildDrmSessionManager()()` |
| `https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#buildExoPlayer(androidx.media3.test.utils.HostActivity,android.view.Surface,androidx.media3.exoplayer.trackselection.MappingTrackSelector)( https://developer.android.com/reference/androidx/media3/test/utils/HostActivity host, https://developer.android.com/reference/android/view/Surface.html surface, https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/MappingTrackSelector trackSelector )` |
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#buildSource(androidx.media3.test.utils.HostActivity,androidx.media3.exoplayer.drm.DrmSessionManager,android.widget.FrameLayout)( https://developer.android.com/reference/androidx/media3/test/utils/HostActivity host, https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager drmSessionManager, https://developer.android.com/reference/android/widget/FrameLayout.html overlayFrameLayout )` |
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/DefaultTrackSelector` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#buildTrackSelector(androidx.media3.test.utils.HostActivity)(https://developer.android.com/reference/androidx/media3/test/utils/HostActivity host)` |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#logMetrics(androidx.media3.exoplayer.DecoderCounters,androidx.media3.exoplayer.DecoderCounters)( https://developer.android.com/reference/androidx/media3/exoplayer/DecoderCounters audioCounters, https://developer.android.com/reference/androidx/media3/exoplayer/DecoderCounters videoCounters )` |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#onPlayerErrorInternal(androidx.media3.exoplayer.ExoPlaybackException)(https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlaybackException error)` |
| `boolean` | `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#shouldStopTest(androidx.media3.common.Player)(https://developer.android.com/reference/androidx/media3/common/Player player)` Returns whether the test should be stopped when playback state changes. |

## 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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Size(max = 23) https://developer.android.com/reference/java/lang/String.html 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 `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Size(max = 23) https://developer.android.com/reference/java/lang/String.html 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 `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#MAX_PLAYING_TIME_DISCREPANCY_MS()` of the specified value. `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#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 `https://developer.android.com/reference/androidx/media3/test/utils/ExoHostedTest#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 `https://developer.android.com/reference/androidx/media3/test/utils/HostActivity.HostedTest#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 `https://developer.android.com/reference/androidx/media3/test/utils/HostActivity` has been resumed and its `https://developer.android.com/reference/android/view/Surface.html` has been created.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/HostActivity host` | The `https://developer.android.com/reference/androidx/media3/test/utils/HostActivity` in which the test is being run. |
| `https://developer.android.com/reference/android/view/Surface.html surface` | The `https://developer.android.com/reference/android/view/Surface.html`. |
| `https://developer.android.com/reference/android/widget/FrameLayout.html overlayFrameLayout` | A `https://developer.android.com/reference/android/widget/FrameLayout.html` that is on top of the surface. |

### setSchedule

```
public final void setSchedule(ActionSchedule schedule)
```

Sets a schedule to be applied during the test.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/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)
```

### shouldStopTest

```
protected boolean shouldStopTest(Player player)
```

Returns whether the test should be stopped when playback state changes.

Subclasses may override to delay stopping the test (e.g., waiting for asynchronous postroll ads to finish).