@UnstableApi
class PlayerMessage


Defines a player message which can be sent with a Sender and received by a .

Summary

Nested types

A sender for messages.

A target for messages.

Public constructors

PlayerMessage(
    sender: PlayerMessage.Sender!,
    target: PlayerMessage.Target!,
    timeline: Timeline!,
    defaultMediaItemIndex: Int,
    clock: Clock!,
    defaultLooper: Looper!
)

Creates a new message.

Public functions

synchronized Boolean

Blocks until after the message has been delivered or the player is no longer able to deliver the message.

synchronized Boolean

Blocks until after the message has been delivered or the player is no longer able to deliver the message or the specified timeout elapsed.

synchronized PlayerMessage!

Cancels the message delivery.

synchronized Unit
markAsProcessed(isDelivered: Boolean)

Marks the message as processed.

PlayerMessage!

Sends the message.

PlayerMessage!

This function is deprecated.

Use setLooper instead.

PlayerMessage!

Sets a position in the current media item at which the message will be delivered.

PlayerMessage!
@CanIgnoreReturnValue
setPosition(mediaItemIndex: Int, positionMs: Long)

Sets a position in a media item at which the message will be delivered.

Public constructors

PlayerMessage

PlayerMessage(
    sender: PlayerMessage.Sender!,
    target: PlayerMessage.Target!,
    timeline: Timeline!,
    defaultMediaItemIndex: Int,
    clock: Clock!,
    defaultLooper: Looper!
)

Creates a new message.

Parameters
sender: PlayerMessage.Sender!

The Sender used to send the message.

target: PlayerMessage.Target!

The Target the message is sent to.

timeline: Timeline!

The timeline used when setting the position with setPosition. If set to EMPTY, any position can be specified.

defaultMediaItemIndex: Int

The default media item index in the timeline when no other media item index is specified.

clock: Clock!

The Clock.

defaultLooper: Looper!

The default Looper to send the message on when no other looper is specified.

Public functions

blockUntilDelivered

synchronized fun blockUntilDelivered(): Boolean

Blocks until after the message has been delivered or the player is no longer able to deliver the message.

Note that this method must not be called if the current thread is the same thread used by the message looper as it would cause a deadlock.

Returns
Boolean

Whether the message was delivered successfully.

Throws
java.lang.IllegalStateException

If this method is called before send.

java.lang.IllegalStateException

If this method is called on the same thread used by the message looper.

java.lang.InterruptedException

If the current thread is interrupted while waiting for the message to be delivered.

blockUntilDelivered

synchronized fun blockUntilDelivered(timeoutMs: Long): Boolean

Blocks until after the message has been delivered or the player is no longer able to deliver the message or the specified timeout elapsed.

Note that this method must not be called if the current thread is the same thread used by the message looper as it would cause a deadlock.

Parameters
timeoutMs: Long

The timeout in milliseconds.

Returns
Boolean

Whether the message was delivered successfully.

Throws
java.lang.IllegalStateException

If this method is called before send.

java.lang.IllegalStateException

If this method is called on the same thread used by the message looper.

java.util.concurrent.TimeoutException

If the timeoutMs elapsed and this message has not been delivered and the player is still able to deliver the message.

java.lang.InterruptedException

If the current thread is interrupted while waiting for the message to be delivered.

cancel

@CanIgnoreReturnValue
synchronized fun cancel(): PlayerMessage!

Cancels the message delivery.

Returns
PlayerMessage!

This message.

Throws
java.lang.IllegalStateException

If this method is called before send.

markAsProcessed

synchronized fun markAsProcessed(isDelivered: Boolean): Unit

Marks the message as processed. Should only be called by a Sender and may be called multiple times.

Parameters
isDelivered: Boolean

Whether the message has been delivered to its target. The message is considered as being delivered when this method has been called with isDelivered set to true at least once.

send

@CanIgnoreReturnValue
fun send(): PlayerMessage!

Sends the message. If the target throws an ExoPlaybackException then it is propagated out of the player as an error using onPlayerError.

Returns
PlayerMessage!

This message.

Throws
java.lang.IllegalStateException

If this message has already been sent.

setHandler

@CanIgnoreReturnValue
fun setHandler(handler: Handler!): PlayerMessage!

setPosition

@CanIgnoreReturnValue
fun setPosition(positionMs: Long): PlayerMessage!

Sets a position in the current media item at which the message will be delivered.

Parameters
positionMs: Long

The position in the current media item at which the message will be sent, in milliseconds, or TIME_END_OF_SOURCE to deliver the message at the end of the current media item.

Returns
PlayerMessage!

This message.

Throws
java.lang.IllegalStateException

If send has already been called.

setPosition

@CanIgnoreReturnValue
fun setPosition(mediaItemIndex: Int, positionMs: Long): PlayerMessage!

Sets a position in a media item at which the message will be delivered.

Parameters
mediaItemIndex: Int

The index of the media item at which the message will be sent.

positionMs: Long

The position in the media item with index mediaItemIndex at which the message will be sent, in milliseconds, or TIME_END_OF_SOURCE to deliver the message at the end of the media item with index mediaItemIndex.

Returns
PlayerMessage!

This message.

Throws
androidx.media3.common.IllegalSeekPositionException

If the timeline returned by getTimeline is not empty and the provided media item index is not within the bounds of the timeline.

java.lang.IllegalStateException

If send has already been called.

Public properties

deleteAfterDelivery

var deleteAfterDeliveryBoolean

isCanceled

val isCanceledBoolean

looper

var looperLooper!

mediaItemIndex

val mediaItemIndexInt

payload

var payloadAny?

positionMs

val positionMsLong

target

val targetPlayerMessage.Target!

timeline

val timelineTimeline!

type

var typeInt