@UnstableApi
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 companion functions

PlayerFence
futureWhen(player: Player)

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

Public functions

ListenableFuture<Void?>

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

PlayerFence

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

ListenableFuture<Void?>
passesContentPosition(targetPositionMs: Long)

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

ListenableFuture<Void?>

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

Public companion functions

futureWhen

fun futureWhen(player: Player): PlayerFence

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

Public functions

entersPlaybackState

fun entersPlaybackState(targetState: @Player.State Int): ListenableFuture<Void?>

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.

ignoringNonFatalErrors

fun ignoringNonFatalErrors(): PlayerFence

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

fun passesContentPosition(targetPositionMs: Long): ListenableFuture<Void?>

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

fun rendersFirstFrame(): ListenableFuture<Void?>

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

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