Package com.google.android.exoplayer2.testutil

## Class ExoHostedTest

- java.lang.Object
- - com.google.android.exoplayer2.testutil.ExoHostedTest

- All Implemented Interfaces:
    `AnalyticsListener`, `HostActivity.HostedTest`

      public abstract class ExoHostedTest
      extends Object
      implements AnalyticsListener, HostActivity.HostedTest

  A `HostActivity.HostedTest` for `ExoPlayer` playback tests.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.analytics.AnalyticsListener

      `AnalyticsListener.EventFlags, AnalyticsListener.Events, AnalyticsListener.EventTime`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static long` | `EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS` |
    `static long` | `EXPECTED_PLAYING_TIME_UNSET` |
    `static long` | `MAX_PLAYING_TIME_DISCREPANCY_MS` |
    `protected String` | `tag` |

    - ### Fields inherited from interface com.google.android.exoplayer2.analytics.AnalyticsListener

      `EVENT_AUDIO_ATTRIBUTES_CHANGED, EVENT_AUDIO_CODEC_ERROR, EVENT_AUDIO_DECODER_INITIALIZED, EVENT_AUDIO_DECODER_RELEASED, EVENT_AUDIO_DISABLED, EVENT_AUDIO_ENABLED, EVENT_AUDIO_INPUT_FORMAT_CHANGED, EVENT_AUDIO_POSITION_ADVANCING, EVENT_AUDIO_SESSION_ID, EVENT_AUDIO_SINK_ERROR, EVENT_AUDIO_UNDERRUN, EVENT_AVAILABLE_COMMANDS_CHANGED, EVENT_BANDWIDTH_ESTIMATE, EVENT_DOWNSTREAM_FORMAT_CHANGED, EVENT_DRM_KEYS_LOADED, EVENT_DRM_KEYS_REMOVED, EVENT_DRM_KEYS_RESTORED, EVENT_DRM_SESSION_ACQUIRED, EVENT_DRM_SESSION_MANAGER_ERROR, EVENT_DRM_SESSION_RELEASED, EVENT_DROPPED_VIDEO_FRAMES, EVENT_IS_LOADING_CHANGED, EVENT_IS_PLAYING_CHANGED, EVENT_LOAD_CANCELED, EVENT_LOAD_COMPLETED, EVENT_LOAD_ERROR, EVENT_LOAD_STARTED, EVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGED, EVENT_MEDIA_ITEM_TRANSITION, EVENT_MEDIA_METADATA_CHANGED, EVENT_METADATA, EVENT_PLAY_WHEN_READY_CHANGED, EVENT_PLAYBACK_PARAMETERS_CHANGED, EVENT_PLAYBACK_STATE_CHANGED, EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED, EVENT_PLAYER_ERROR, EVENT_PLAYER_RELEASED, EVENT_PLAYLIST_METADATA_CHANGED, EVENT_POSITION_DISCONTINUITY, EVENT_RENDERED_FIRST_FRAME, EVENT_REPEAT_MODE_CHANGED, EVENT_SEEK_BACK_INCREMENT_CHANGED, EVENT_SEEK_FORWARD_INCREMENT_CHANGED, EVENT_SHUFFLE_MODE_ENABLED_CHANGED, EVENT_SKIP_SILENCE_ENABLED_CHANGED, EVENT_STATIC_METADATA_CHANGED, EVENT_SURFACE_SIZE_CHANGED, EVENT_TIMELINE_CHANGED, EVENT_TRACKS_CHANGED, EVENT_UPSTREAM_DISCARDED, EVENT_VIDEO_CODEC_ERROR, EVENT_VIDEO_DECODER_INITIALIZED, EVENT_VIDEO_DECODER_RELEASED, EVENT_VIDEO_DISABLED, EVENT_VIDEO_ENABLED, EVENT_VIDEO_FRAME_PROCESSING_OFFSET, EVENT_VIDEO_INPUT_FORMAT_CHANGED, EVENT_VIDEO_SIZE_CHANGED, EVENT_VOLUME_CHANGED`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ExoHostedTest​(String tag, boolean fullPlaybackNoSeeking)` |
    `ExoHostedTest​(String tag, long expectedPlayingTimeMs, boolean failOnPlayerError)` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected void` | `assertPassed​(DecoderCounters audioCounters, DecoderCounters videoCounters)` |
    `boolean` | `blockUntilStopped​(long timeoutMs)` | Called on the main thread to block until the test has stopped or `HostActivity.HostedTest.forceStop()` is called.
    `protected DrmSessionManager` | `buildDrmSessionManager()` |
    `protected SimpleExoPlayer` | `buildExoPlayer​(HostActivity host, Surface surface, MappingTrackSelector trackSelector)` |
    `protected abstract MediaSource` | `buildSource​(HostActivity host, DrmSessionManager drmSessionManager, FrameLayout overlayFrameLayout)` |
    `protected DefaultTrackSelector` | `buildTrackSelector​(HostActivity host)` |
    `boolean` | `forceStop()` | Called on the main thread to force stop the test (if it is not stopped already).
    `protected void` | `logMetrics​(DecoderCounters audioCounters, DecoderCounters videoCounters)` |
    `void` | `onAudioDisabled​(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters)` | Called when an audio renderer is disabled.
    `void` | `onEvents​(Player player, AnalyticsListener.Events events)` | Called after one or more events occurred.
    `void` | `onFinished()` | Called on the test thread after the test has finished and been stopped.
    `protected void` | `onPlayerErrorInternal​(ExoPlaybackException error)` |
    `void` | `onStart​(HostActivity host, Surface surface, FrameLayout overlayFrameLayout)` | Called on the main thread when the test is started.
    `void` | `onVideoDisabled​(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters)` | Called when a video renderer is disabled.
    `void` | `setSchedule​(ActionSchedule schedule)` | Sets a schedule to be applied during the test.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.google.android.exoplayer2.analytics.AnalyticsListener

      `onAudioAttributesChanged, onAudioCodecError, onAudioDecoderInitialized, onAudioDecoderInitialized, onAudioDecoderReleased, onAudioEnabled, onAudioInputFormatChanged, onAudioInputFormatChanged, onAudioPositionAdvancing, onAudioSessionIdChanged, onAudioSinkError, onAudioUnderrun, onAvailableCommandsChanged, onBandwidthEstimate, onDecoderDisabled, onDecoderEnabled, onDecoderInitialized, onDecoderInputFormatChanged, onDownstreamFormatChanged, onDrmKeysLoaded, onDrmKeysRemoved, onDrmKeysRestored, onDrmSessionAcquired, onDrmSessionAcquired, onDrmSessionManagerError, onDrmSessionReleased, onDroppedVideoFrames, onIsLoadingChanged, onIsPlayingChanged, onLoadCanceled, onLoadCompleted, onLoadError, onLoadingChanged, onLoadStarted, onMaxSeekToPreviousPositionChanged, onMediaItemTransition, onMediaMetadataChanged, onMetadata, onPlaybackParametersChanged, onPlaybackStateChanged, onPlaybackSuppressionReasonChanged, onPlayerError, onPlayerReleased, onPlayerStateChanged, onPlaylistMetadataChanged, onPlayWhenReadyChanged, onPositionDiscontinuity, onPositionDiscontinuity, onRenderedFirstFrame, onRepeatModeChanged, onSeekBackIncrementChanged, onSeekForwardIncrementChanged, onSeekProcessed, onSeekStarted, onShuffleModeChanged, onSkipSilenceEnabledChanged, onStaticMetadataChanged, onSurfaceSizeChanged, onTimelineChanged, onTracksChanged, onUpstreamDiscarded, onVideoCodecError, onVideoDecoderInitialized, onVideoDecoderInitialized, onVideoDecoderReleased, onVideoEnabled, onVideoFrameProcessingOffset, onVideoInputFormatChanged, onVideoInputFormatChanged, onVideoSizeChanged, onVideoSizeChanged, onVolumeChanged`

- - ### Field Detail

    - #### MAX_PLAYING_TIME_DISCREPANCY_MS

          public static final long MAX_PLAYING_TIME_DISCREPANCY_MS

      See Also:
        Constant Field Values

    - #### EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS

          public static final long EXPECTED_PLAYING_TIME_MEDIA_DURATION_MS

      See Also:
        Constant Field Values

    - #### EXPECTED_PLAYING_TIME_UNSET

          public static final long EXPECTED_PLAYING_TIME_UNSET

      See Also:
        Constant Field Values

    - #### tag

          protected final String tag

  - ### Constructor Detail

    - #### ExoHostedTest

          public ExoHostedTest​(String tag,
                               boolean fullPlaybackNoSeeking)

      Parameters:
        `tag` - A tag to use for logging.
        `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​(String tag,
                               long expectedPlayingTimeMs,
                               boolean failOnPlayerError)

      Parameters:
        `tag` - A tag to use for logging.
        `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.
        `failOnPlayerError` - Whether a player error should be considered a test failure.

  - ### Method Detail

    - #### setSchedule

          public final void setSchedule​(ActionSchedule schedule)

      Sets a schedule to be applied during the test.
      Parameters:
        `schedule` - The schedule.

    - #### onStart

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

      Description copied from interface: `HostActivity.HostedTest`
      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.

      Specified by:
        `onStart` in interface `HostActivity.HostedTest`
      Parameters:
        `host` - The `HostActivity` in which the test is being run.
        `surface` - The `Surface`.
        `overlayFrameLayout` - A `FrameLayout` that is on top of the surface.

    - #### blockUntilStopped

          public final boolean blockUntilStopped​(long timeoutMs)

      Description copied from interface: `HostActivity.HostedTest`
      Called on the main thread to block until the test has stopped or `HostActivity.HostedTest.forceStop()` is called.
      Specified by:
        `blockUntilStopped` in interface `HostActivity.HostedTest`
      Parameters:
        `timeoutMs` - The maximum time to block in milliseconds.
      Returns:
        Whether the test has stopped successful.

    - #### forceStop

          public final boolean forceStop()

      Description copied from interface: `HostActivity.HostedTest`
      Called on the main thread to force stop the test (if it is not stopped already).
      Specified by:
        `forceStop` in interface `HostActivity.HostedTest`
      Returns:
        Whether the test was forced stopped.

    - #### onFinished

          public final void onFinished()

      Description copied from interface: `HostActivity.HostedTest`
      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.

      Specified by:
        `onFinished` in interface `HostActivity.HostedTest`

    - #### onEvents

          public void onEvents​(Player player,
                               AnalyticsListener.Events events)

      Description copied from interface: `AnalyticsListener`
      Called after one or more events occurred.

      State changes and events that happen within one `Looper` message queue iteration are reported together and only after all individual callbacks were triggered.

      Listeners should prefer this method over individual callbacks in the following cases:

      - They intend to trigger the same logic for multiple events (e.g. when updating a UI for both `AnalyticsListener.onPlaybackStateChanged(EventTime, int)` and `AnalyticsListener.onPlayWhenReadyChanged(EventTime, boolean, int)`).
      - They need access to the `Player` object to trigger further events (e.g. to call `Player.seekTo(long)` after a `AnalyticsListener.onMediaItemTransition(EventTime, MediaItem, int)`).
      - They intend to use multiple state values together or in combination with `Player` getter methods. For example using `Player.getCurrentWindowIndex()` with the `timeline` provided in `AnalyticsListener.onTimelineChanged(EventTime, int)` is only safe from within this method.
      - They are interested in events that logically happened together (e.g `AnalyticsListener.onPlaybackStateChanged(EventTime, int)` to `Player.STATE_BUFFERING` because of `AnalyticsListener.onMediaItemTransition(EventTime, MediaItem, int)`).
      Specified by:
        `onEvents` in interface `AnalyticsListener`
      Parameters:
        `player` - The `Player`.
        `events` - The `AnalyticsListener.Events` that occurred in this iteration.

    - #### onAudioDisabled

          public void onAudioDisabled​(AnalyticsListener.EventTime eventTime,
                                      DecoderCounters decoderCounters)

      Description copied from interface: `AnalyticsListener`
      Called when an audio renderer is disabled.
      Specified by:
        `onAudioDisabled` in interface `AnalyticsListener`
      Parameters:
        `eventTime` - The event time.
        `decoderCounters` - `DecoderCounters` that were updated by the renderer.

    - #### onVideoDisabled

          public void onVideoDisabled​(AnalyticsListener.EventTime eventTime,
                                      DecoderCounters decoderCounters)

      Description copied from interface: `AnalyticsListener`
      Called when a video renderer is disabled.
      Specified by:
        `onVideoDisabled` in interface `AnalyticsListener`
      Parameters:
        `eventTime` - The event time.
        `decoderCounters` - `DecoderCounters` that were updated by the renderer.

    - #### buildDrmSessionManager

          protected DrmSessionManager buildDrmSessionManager()

    - #### buildTrackSelector

          protected DefaultTrackSelector buildTrackSelector​(HostActivity host)

    - #### buildExoPlayer

          protected SimpleExoPlayer buildExoPlayer​(HostActivity host,
                                                   Surface surface,
                                                   MappingTrackSelector trackSelector)

    - #### buildSource

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

    - #### onPlayerErrorInternal

          protected void onPlayerErrorInternal​(ExoPlaybackException error)

    - #### logMetrics

          protected void logMetrics​(DecoderCounters audioCounters,
                                    DecoderCounters videoCounters)

    - #### assertPassed

          protected void assertPassed​(DecoderCounters audioCounters,
                                      DecoderCounters videoCounters)