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
AHostActivity.HostedTestforExoPlayerplayback 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 longEXPECTED_PLAYING_TIME_MEDIA_DURATION_MSstatic longEXPECTED_PLAYING_TIME_UNSETstatic longMAX_PLAYING_TIME_DISCREPANCY_MSprotected Stringtag-
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_CUES, EVENT_DEVICE_INFO_CHANGED, EVENT_DEVICE_VOLUME_CHANGED, 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_SURFACE_SIZE_CHANGED, EVENT_TIMELINE_CHANGED, EVENT_TRACK_SELECTION_PARAMETERS_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 voidassertPassed(DecoderCounters audioCounters, DecoderCounters videoCounters)booleanblockUntilStopped(long timeoutMs)Called on the main thread to block until the test has stopped orHostActivity.HostedTest.forceStop()is called.protected DrmSessionManagerbuildDrmSessionManager()protected ExoPlayerbuildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector)protected abstract MediaSourcebuildSource(HostActivity host, DrmSessionManager drmSessionManager, FrameLayout overlayFrameLayout)protected DefaultTrackSelectorbuildTrackSelector(HostActivity host)booleanforceStop()Called on the main thread to force stop the test (if it is not stopped already).protected voidlogMetrics(DecoderCounters audioCounters, DecoderCounters videoCounters)voidonAudioDisabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters)Called when an audio renderer is disabled.voidonEvents(Player player, AnalyticsListener.Events events)Called after one or more events occurred.voidonFinished()Called on the test thread after the test has finished and been stopped.protected voidonPlayerErrorInternal(ExoPlaybackException error)voidonStart(HostActivity host, Surface surface, FrameLayout overlayFrameLayout)Called on the main thread when the test is started.voidonVideoDisabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters)Called when a video renderer is disabled.voidsetSchedule(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, onCues, onCues, onDeviceInfoChanged, onDeviceVolumeChanged, onDownstreamFormatChanged, onDrmKeysLoaded, onDrmKeysRemoved, onDrmKeysRestored, onDrmSessionAcquired, onDrmSessionAcquired, onDrmSessionManagerError, onDrmSessionReleased, onDroppedVideoFrames, onIsLoadingChanged, onIsPlayingChanged, onLoadCanceled, onLoadCompleted, onLoadError, onLoadingChanged, onLoadStarted, onMaxSeekToPreviousPositionChanged, onMediaItemTransition, onMediaMetadataChanged, onMetadata, onPlaybackParametersChanged, onPlaybackStateChanged, onPlaybackSuppressionReasonChanged, onPlayerError, onPlayerErrorChanged, onPlayerReleased, onPlayerStateChanged, onPlaylistMetadataChanged, onPlayWhenReadyChanged, onPositionDiscontinuity, onPositionDiscontinuity, onRenderedFirstFrame, onRepeatModeChanged, onSeekBackIncrementChanged, onSeekForwardIncrementChanged, onSeekStarted, onShuffleModeChanged, onSkipSilenceEnabledChanged, onSurfaceSizeChanged, onTimelineChanged, onTracksChanged, onTrackSelectionParametersChanged, 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(@Size(max=23L) 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 withinMAX_PLAYING_TIME_DISCREPANCY_MSof the media duration. If set to false, the test will not assert an expected playing time.
-
ExoHostedTest
public ExoHostedTest(@Size(max=23L) 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 withinMAX_PLAYING_TIME_DISCREPANCY_MSof the specified value.EXPECTED_PLAYING_TIME_MEDIA_DURATION_MSshould be passed to assert that the expected playing time equals the duration of the media being played. ElseEXPECTED_PLAYING_TIME_UNSETshould 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.HostedTestCalled on the main thread when the test is started.The test will not be started until the
HostActivityhas been resumed and itsSurfacehas been created.- Specified by:
onStartin interfaceHostActivity.HostedTest- Parameters:
host- TheHostActivityin which the test is being run.surface- TheSurface.overlayFrameLayout- AFrameLayoutthat is on top of the surface.
-
blockUntilStopped
public final boolean blockUntilStopped(long timeoutMs)
Description copied from interface:HostActivity.HostedTestCalled on the main thread to block until the test has stopped orHostActivity.HostedTest.forceStop()is called.- Specified by:
blockUntilStoppedin interfaceHostActivity.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.HostedTestCalled on the main thread to force stop the test (if it is not stopped already).- Specified by:
forceStopin interfaceHostActivity.HostedTest- Returns:
- Whether the test was forced stopped.
-
onFinished
public final void onFinished()
Description copied from interface:HostActivity.HostedTestCalled 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:
onFinishedin interfaceHostActivity.HostedTest
-
onEvents
public void onEvents(Player player, AnalyticsListener.Events events)
Description copied from interface:AnalyticsListenerCalled after one or more events occurred.State changes and events that happen within one
Loopermessage 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)andAnalyticsListener.onPlayWhenReadyChanged(EventTime, boolean, int)). - They need access to the
Playerobject to trigger further events (e.g. to callPlayer.seekTo(long)after aAnalyticsListener.onMediaItemTransition(EventTime, MediaItem, int)). - They intend to use multiple state values together or in combination with
Playergetter methods. For example usingPlayer.getCurrentMediaItemIndex()with thetimelineprovided inAnalyticsListener.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)toPlayer.STATE_BUFFERINGbecause ofAnalyticsListener.onMediaItemTransition(EventTime, MediaItem, int)).
- Specified by:
onEventsin interfaceAnalyticsListener- Parameters:
player- ThePlayer.events- TheAnalyticsListener.Eventsthat occurred in this iteration.
- They intend to trigger the same logic for multiple events (e.g. when updating a UI for
both
-
onAudioDisabled
public void onAudioDisabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters)
Description copied from interface:AnalyticsListenerCalled when an audio renderer is disabled.- Specified by:
onAudioDisabledin interfaceAnalyticsListener- Parameters:
eventTime- The event time.decoderCounters-DecoderCountersthat were updated by the renderer.
-
onVideoDisabled
public void onVideoDisabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters)
Description copied from interface:AnalyticsListenerCalled when a video renderer is disabled.- Specified by:
onVideoDisabledin interfaceAnalyticsListener- Parameters:
eventTime- The event time.decoderCounters-DecoderCountersthat were updated by the renderer.
-
buildDrmSessionManager
protected DrmSessionManager buildDrmSessionManager()
-
buildTrackSelector
protected DefaultTrackSelector buildTrackSelector(HostActivity host)
-
buildExoPlayer
protected ExoPlayer 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)
-
-