# 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
abstract class ExoHostedTest : HostActivity.HostedTest
```

<br />

*** ** * ** ***

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

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/ExoHostedTest#EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS() = -2` |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/ExoHostedTest#EXPECTED_PLAYING_TIME_UNSET() = -1` |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/ExoHostedTest#MAX_PLAYING_TIME_DISCREPANCY_MS() = 5000` |

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

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

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

| ### Protected properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/ExoHostedTest#tag()` |

## Constants

### EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS

```
const val EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS = -2: Long
```

### EXPECTED_PLAYING_TIME_UNSET

```
const val EXPECTED_PLAYING_TIME_UNSET = -1: Long
```

### MAX_PLAYING_TIME_DISCREPANCY_MS

```
const val MAX_PLAYING_TIME_DISCREPANCY_MS = 5000: Long
```

## Public constructors

### ExoHostedTest

```
ExoHostedTest(tag: @Size(max = 23) String!, fullPlaybackNoSeeking: Boolean)
```

| Parameters |
|---|---|
| `tag: @https://developer.android.com/reference/kotlin/androidx/annotation/Size(max = 23) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | A tag to use for logging. |
| `fullPlaybackNoSeeking: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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/kotlin/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

```
ExoHostedTest(
    tag: @Size(max = 23) String!,
    expectedPlayingTimeMs: Long,
    failOnPlayerError: Boolean
)
```

| Parameters |
|---|---|
| `tag: @https://developer.android.com/reference/kotlin/androidx/annotation/Size(max = 23) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | A tag to use for logging. |
| `expectedPlayingTimeMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | 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/kotlin/androidx/media3/test/utils/ExoHostedTest#MAX_PLAYING_TIME_DISCREPANCY_MS()` of the specified value. `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/test/utils/ExoHostedTest#EXPECTED_PLAYING_TIME_UNSET()` should be passed to indicate that the test should not assert an expected playing time. |
| `failOnPlayerError: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether a player error should be considered a test failure. |

## Public functions

### blockUntilStopped

```
fun blockUntilStopped(timeoutMs: Long): Boolean
```

Called on the main thread to block until the test has stopped or `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/HostActivity.HostedTest#forceStop()` is called.

| Parameters |
|---|---|
| `timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The maximum time to block in milliseconds. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the test has stopped successful. |

### forceStop

```
fun forceStop(): Boolean
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the test was forced stopped. |

### onFinished

```
fun onFinished(): Unit
```

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

```
fun onStart(
    host: HostActivity!,
    surface: Surface!,
    overlayFrameLayout: FrameLayout!
): Unit
```

Called on the main thread when the test is started.

The test will not be started until the `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/HostActivity` has been resumed and its `https://developer.android.com/reference/android/view/Surface.html` has been created.

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

### setSchedule

```
fun setSchedule(schedule: ActionSchedule!): Unit
```

Sets a schedule to be applied during the test.

| Parameters |
|---|---|
| `schedule: https://developer.android.com/reference/kotlin/androidx/media3/test/utils/ActionSchedule!` | The schedule. |

## Protected functions

### assertPassed

```
protected fun assertPassed(
    audioCounters: DecoderCounters!,
    videoCounters: DecoderCounters!
): Unit
```

### buildDrmSessionManager

```
protected fun buildDrmSessionManager(): DrmSessionManager!
```

### buildExoPlayer

```
protected fun buildExoPlayer(
    host: HostActivity!,
    surface: Surface!,
    trackSelector: MappingTrackSelector!
): ExoPlayer!
```

### buildSource

```
protected abstract fun buildSource(
    host: HostActivity!,
    drmSessionManager: DrmSessionManager!,
    overlayFrameLayout: FrameLayout!
): MediaSource!
```

### buildTrackSelector

```
protected fun buildTrackSelector(host: HostActivity!): DefaultTrackSelector!
```

### logMetrics

```
protected fun logMetrics(
    audioCounters: DecoderCounters!,
    videoCounters: DecoderCounters!
): Unit
```

### onPlayerErrorInternal

```
protected fun onPlayerErrorInternal(error: ExoPlaybackException!): Unit
```

### shouldStopTest

```
protected fun shouldStopTest(player: Player!): Boolean
```

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

## Protected properties

### tag

```
protected val tag: String!
```