PlayerFenceKt


public final class PlayerFenceKt


Summary

Public methods

static final void
@UnstableApi
awaitContentPositionAtLeast(
    @NonNull Player receiver,
    long targetPositionMs,
    boolean failOnNonFatalErrors
)

Suspends until the content position reaches (or passes) targetPositionMs in the current media item.

static final void
@UnstableApi
awaitFirstFrameRendered(
    @NonNull Player receiver,
    boolean failOnNonFatalErrors
)

Suspends until Player.Listener.onRenderedFirstFrame is invoked.

static final void
@UnstableApi
awaitPlaybackState(
    @NonNull Player receiver,
    @Player.State int targetState,
    boolean failOnNonFatalErrors
)

Suspends until the player enters the provided targetState.

Public methods

awaitContentPositionAtLeast

@UnstableApi
public static final void awaitContentPositionAtLeast(
    @NonNull Player receiver,
    long targetPositionMs,
    boolean failOnNonFatalErrors
)

Suspends until the content position reaches (or passes) targetPositionMs in the current media item.

This makes some assumptions:

  1. The condition completes immediately if Player.getContentPosition is already at least targetPositionMs.

  2. Seeking past the target position satisfies the condition.

  3. If playback ends, or the media item changes, before the target position is reached, an exception is thrown.

Must be called on the player's application looper thread.

awaitFirstFrameRendered

@UnstableApi
public static final void awaitFirstFrameRendered(
    @NonNull Player receiver,
    boolean failOnNonFatalErrors
)

Suspends until Player.Listener.onRenderedFirstFrame is invoked.

This should be called before the callback has been invoked (e.g. before calling Player.prepare), otherwise it risks awaiting forever.

Must be called on the player's application looper thread.

awaitPlaybackState

@UnstableApi
public static final void awaitPlaybackState(
    @NonNull Player receiver,
    @Player.State int targetState,
    boolean failOnNonFatalErrors
)

Suspends until the player enters the provided targetState.

If the player is already in the provided targetState this returns immediately.

Must be called on the player's application looper thread.

Throws
IllegalStateException

if not called on the player's application looper thread.