PlayerExtensionsKt


public final class PlayerExtensionsKt


Summary

Public methods

static final @NonNull Void
@UnstableApi
listen(
    @NonNull Player receiver,
    @ExtensionFunctionType @NonNull Function2<@NonNull Player, @NonNull Player.EventsUnit> onEvents
)

Continuously listens to the Player.Listener.onEvents callback, passing the received Player.Events to the provided onEvents function.

Public methods

@UnstableApi
public static final @NonNull Void listen(
    @NonNull Player receiver,
    @ExtensionFunctionType @NonNull Function2<@NonNull Player, @NonNull Player.EventsUnit> onEvents
)

Continuously listens to the Player.Listener.onEvents callback, passing the received Player.Events to the provided onEvents function.

This function can be called from any thread. The onEvents function will be invoked on the thread associated with Player.getApplicationLooper.

If, during the execution of onEvents, an exception is thrown, the coroutine corresponding to listening to the Player will be terminated. Any used resources will be cleaned up (e.g. removing of the listeners) and exception will be re-thrown right after the last suspension point.

Parameters
@ExtensionFunctionType @NonNull Function2<@NonNull Player, @NonNull Player.EventsUnit> onEvents

The function to handle player events.

Returns
@NonNull Void

Nothing This function never returns normally. It will either continue indefinitely or terminate due to an exception or cancellation.