Class ExoPlayerTestRunner

    • Method Detail

      • start

        @CanIgnoreReturnValue
        public ExoPlayerTestRunner start()
        Starts the test runner on its own thread. This will trigger the creation of the player, the listener registration, the start of the action schedule, the initial set of media items and the preparation of the player.
        Returns:
        This test runner.
      • start

        @CanIgnoreReturnValue
        public ExoPlayerTestRunner start​(boolean doPrepare)
        Starts the test runner on its own thread. This will trigger the creation of the player, the listener registration, the start of the action schedule and the initial set of media items.
        Parameters:
        doPrepare - Whether the player should be prepared.
        Returns:
        This test runner.
      • blockUntilEnded

        @CanIgnoreReturnValue
        public ExoPlayerTestRunner blockUntilEnded​(long timeoutMs)
                                            throws Exception
        Blocks the current thread until the test runner finishes. A test is deemed to be finished when the playback state transitioned to Player.STATE_ENDED or Player.STATE_IDLE for the specified number of times. The test also finishes when an ExoPlaybackException is thrown.
        Parameters:
        timeoutMs - The maximum time to wait for the test runner to finish. If this time elapsed the method will throw a TimeoutException.
        Returns:
        This test runner.
        Throws:
        Exception - If any exception occurred during playback, release, or due to a timeout.
      • blockUntilActionScheduleFinished

        @CanIgnoreReturnValue
        public ExoPlayerTestRunner blockUntilActionScheduleFinished​(long timeoutMs)
                                                             throws TimeoutException,
                                                                    InterruptedException
        Blocks the current thread until the action schedule finished. This does not release the test runner and the test must still call blockUntilEnded(long).
        Parameters:
        timeoutMs - The maximum time to wait for the action schedule to finish.
        Returns:
        This test runner.
        Throws:
        TimeoutException - If the action schedule did not finish within the specified timeout.
        InterruptedException - If the test thread gets interrupted while waiting.
      • assertTimelinesSame

        public void assertTimelinesSame​(Timeline... timelines)
        Asserts that the timelines reported by Player.Listener.onTimelineChanged(Timeline, int) are the same to the provided timelines. This assert differs from testing equality by not comparing period ids which may be different due to id mapping of child source period ids.
        Parameters:
        timelines - A list of expected Timelines.
      • assertPlayedPeriodIndices

        public void assertPlayedPeriodIndices​(Integer... periodIndices)
        Asserts that the indices of played periods is equal to the provided list of periods. A period is considered to be played if it was the current period after a position discontinuity or a media source preparation. When the same period is repeated automatically due to enabled repeat modes, it is reported twice. Seeks within the current period are not reported.
        Parameters:
        periodIndices - A list of expected period indices.
      • onMediaItemTransition

        public void onMediaItemTransition​(@Nullable
                                          MediaItem mediaItem,
                                          @MediaItemTransitionReason
                                          @com.google.android.exoplayer2.Player.MediaItemTransitionReason int reason)
        Description copied from interface: Player.Listener
        Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode.

        Note that this callback is also called when the playlist becomes non-empty or empty as a consequence of a playlist change.

        Player.Listener.onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper message queue iteration.

        Specified by:
        onMediaItemTransition in interface Player.Listener
        Parameters:
        mediaItem - The MediaItem. May be null if the playlist becomes empty.
        reason - The reason for the transition.
      • onPlayerError

        public void onPlayerError​(PlaybackException error)
        Description copied from interface: Player.Listener
        Called when an error occurs. The playback state will transition to Player.STATE_IDLE immediately after this method is called. The player instance can still be used, and Player.release() must still be called on the player should it no longer be required.

        Player.Listener.onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper message queue iteration.

        Implementations of Player may pass an instance of a subclass of PlaybackException to this method in order to include more information about the error.

        Specified by:
        onPlayerError in interface Player.Listener
        Parameters:
        error - The error.
      • onPositionDiscontinuity

        public void onPositionDiscontinuity​(Player.PositionInfo oldPosition,
                                            Player.PositionInfo newPosition,
                                            @DiscontinuityReason
                                            @com.google.android.exoplayer2.Player.DiscontinuityReason int reason)
        Description copied from interface: Player.Listener
        Called when a position discontinuity occurs.

        A position discontinuity occurs when the playing period changes, the playback position jumps within the period currently being played, or when the playing period has been skipped or removed.

        Player.Listener.onEvents(Player, Events) will also be called to report this event along with other events that happen in the same Looper message queue iteration.

        Specified by:
        onPositionDiscontinuity in interface Player.Listener
        Parameters:
        oldPosition - The position before the discontinuity.
        newPosition - The position after the discontinuity.
        reason - The Player.DiscontinuityReason responsible for the discontinuity.