PlayerExtensionsKt


public final class PlayerExtensionsKt


Summary

Public methods

static final @NonNull Void
@UnstableApi
listen(
    @NonNull Player receiver,
    @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.

static final @NonNull Void
@UnstableApi
listenTo(
    @NonNull Player receiver,
    @Player.Event int firstEvent,
    @Player.Event int... otherEvents,
    @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,
    @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
@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.

@UnstableApi
public static final @NonNull Void listenTo(
    @NonNull Player receiver,
    @Player.Event int firstEvent,
    @Player.Event int... otherEvents,
    @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. A non-zero number of events has to be specified (hence firstEvent and otherEvents). The order is not important.

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
@Player.Event int firstEvent

One of the events to listen to. Does not have to actually be the first one, since the order is not taken into account. This parameter is separated from otherEvents to avoid creating an array when only one event is needed or avoid accidentally not passing any events.

@Player.Event int... otherEvents

The set of other events to listen for.

@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.