@UnstableApi
public final class PlayerFence


A Java-compatible fluent API for waiting for certain Player conditions.

Kotlin users should strongly prefer directly calling the suspending Player extension functions like awaitPlaybackState instead.

Instances are created via futureWhen.

Summary

Public methods

final @NonNull ListenableFuture<Void>

Returns a future that completes when the player enters the provided targetState.

static final @NonNull PlayerFence

Entry point for Java callers to get a ListenableFuture for a Player condition.

final @NonNull PlayerFence

Returns a new instance that will not fail the future on non-fatal errors.

final @NonNull ListenableFuture<Void>
passesContentPosition(long targetPositionMs)

Returns a future that completes when the content position reaches (or passes) targetPositionMs in the current media item.

final @NonNull ListenableFuture<Void>

Returns a future that completes when Player.Listener.onRenderedFirstFrame is invoked.

Public methods

entersPlaybackState

public final @NonNull ListenableFuture<VoidentersPlaybackState(@Player.State int targetState)

Returns a future that completes when the player enters the provided targetState.

If the player is already in the provided targetState, the future completes immediately.

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

Throws
IllegalStateException

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

futureWhen

public static final @NonNull PlayerFence futureWhen(@NonNull Player player)

Entry point for Java callers to get a ListenableFuture for a Player condition.

ignoringNonFatalErrors

public final @NonNull PlayerFence ignoringNonFatalErrors()

Returns a new instance that will not fail the future on non-fatal errors.

By default, futures will fail if a non-fatal error (e.g. loading error) occurs while waiting.

passesContentPosition

public final @NonNull ListenableFuture<VoidpassesContentPosition(long targetPositionMs)

Returns a future that completes when the content position reaches (or passes) targetPositionMs in the current media item.

See Player.awaitContentPositionAtLeast for assumptions made by this condition.

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

rendersFirstFrame

public final @NonNull ListenableFuture<VoidrendersFirstFrame()

Returns a future that completes when Player.Listener.onRenderedFirstFrame is invoked.

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