PlayerMessage
@UnstableApi
public final class PlayerMessage
Defines a player message which can be sent with a Sender and received by a Target.
Summary
Nested types |
|---|
public interface PlayerMessage.SenderA sender for messages. |
public interface PlayerMessage.TargetA target for messages. |
Public fields |
|
|---|---|
boolean |
|
boolean |
|
Looper |
|
int |
|
@Nullable Object |
|
long |
|
final PlayerMessage.Target |
|
final Timeline |
|
int |
Public constructors |
|---|
PlayerMessage(Creates a new message. |
Public methods |
|
|---|---|
synchronized boolean |
Blocks until after the message has been delivered or the player is no longer able to deliver the message. |
synchronized boolean |
blockUntilDelivered(long timeoutMs)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. |
boolean |
Returns whether the message will be deleted after delivery. |
Looper |
Returns the |
int |
Returns media item index at which the message will be delivered. |
@Nullable Object |
Returns the message payload forwarded to |
long |
Returns position in the media item at |
PlayerMessage.Target |
Returns the target the message is sent to. |
Timeline |
Returns the timeline used for setting the position with |
int |
getType()Returns the message type forwarded to |
synchronized boolean |
Returns whether the message delivery has been canceled. |
synchronized void |
markAsProcessed(boolean isDelivered)Marks the message as processed. |
PlayerMessage |
Sends the message. |
PlayerMessage |
@CanIgnoreReturnValueSets whether the message will be deleted after delivery. |
PlayerMessage |
@CanIgnoreReturnValueSets the |
PlayerMessage |
@CanIgnoreReturnValueSets the message payload forwarded to |
PlayerMessage |
@CanIgnoreReturnValueSets a position in the current media item at which the message will be delivered. |
PlayerMessage |
@CanIgnoreReturnValueSets a position in a media item at which the message will be delivered. |
PlayerMessage |
@CanIgnoreReturnValueSets the message type forwarded to |
Public fields
Public constructors
PlayerMessage
public PlayerMessage(
PlayerMessage.Sender sender,
PlayerMessage.Target target,
Timeline timeline,
int defaultMediaItemIndex,
Clock clock,
Looper defaultLooper
)
Creates a new message.
| Parameters | |
|---|---|
PlayerMessage.Sender sender |
The |
PlayerMessage.Target target |
The |
Timeline timeline |
The timeline used when setting the position with |
int defaultMediaItemIndex |
The default media item index in the |
Clock clock |
The |
Looper defaultLooper |
The default |
Public methods
blockUntilDelivered
synchronized public boolean blockUntilDelivered()
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 |
java.lang.IllegalStateException |
If this method is called on the same thread used by the message |
java.lang.InterruptedException |
If the current thread is interrupted while waiting for the message to be delivered. |
blockUntilDelivered
synchronized public boolean blockUntilDelivered(long timeoutMs)
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 | |
|---|---|
long timeoutMs |
The timeout in milliseconds. |
| Returns | |
|---|---|
boolean |
Whether the message was delivered successfully. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If this method is called before |
java.lang.IllegalStateException |
If this method is called on the same thread used by the message |
java.util.concurrent.TimeoutException |
If the |
java.lang.InterruptedException |
If the current thread is interrupted while waiting for the message to be delivered. |
cancel
@CanIgnoreReturnValue
synchronized public PlayerMessage cancel()
Cancels the message delivery.
| Returns | |
|---|---|
PlayerMessage |
This message. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If this method is called before |
getDeleteAfterDelivery
public boolean getDeleteAfterDelivery()
Returns whether the message will be deleted after delivery.
getMediaItemIndex
public int getMediaItemIndex()
Returns media item index at which the message will be delivered.
getPayload
public @Nullable Object getPayload()
Returns the message payload forwarded to handleMessage.
getPositionMs
public long getPositionMs()
Returns position in the media item at getMediaItemIndex at which the message will be delivered, in milliseconds. If TIME_UNSET, the message will be delivered immediately. If TIME_END_OF_SOURCE, the message will be delivered at the end of the media item at getMediaItemIndex.
getTimeline
public Timeline getTimeline()
Returns the timeline used for setting the position with setPosition.
isCanceled
synchronized public boolean isCanceled()
Returns whether the message delivery has been canceled.
markAsProcessed
synchronized public void markAsProcessed(boolean isDelivered)
Marks the message as processed. Should only be called by a Sender and may be called multiple times.
| Parameters | |
|---|---|
boolean isDelivered |
Whether the message has been delivered to its target. The message is considered as being delivered when this method has been called with |
send
@CanIgnoreReturnValue
public PlayerMessage send()
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. |
setDeleteAfterDelivery
@CanIgnoreReturnValue
public PlayerMessage setDeleteAfterDelivery(boolean deleteAfterDelivery)
Sets whether the message will be deleted after delivery. If false, the message will be resent if playback reaches the specified position again. Only allowed to be false if a position is set with setPosition.
| Parameters | |
|---|---|
boolean deleteAfterDelivery |
Whether the message is deleted after delivery. |
| Returns | |
|---|---|
PlayerMessage |
This message. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If |
setLooper
@CanIgnoreReturnValue
public PlayerMessage setLooper(Looper looper)
Sets the Looper the message is delivered on.
| Returns | |
|---|---|
PlayerMessage |
This message. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If |
setPayload
@CanIgnoreReturnValue
public PlayerMessage setPayload(@Nullable Object payload)
Sets the message payload forwarded to handleMessage.
| Returns | |
|---|---|
PlayerMessage |
This message. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If |
setPosition
@CanIgnoreReturnValue
public PlayerMessage setPosition(long positionMs)
Sets a position in the current media item at which the message will be delivered.
| Parameters | |
|---|---|
long positionMs |
The position in the current media item at which the message will be sent, in milliseconds, or |
| Returns | |
|---|---|
PlayerMessage |
This message. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If |
setPosition
@CanIgnoreReturnValue
public PlayerMessage setPosition(int mediaItemIndex, long positionMs)
Sets a position in a media item at which the message will be delivered.
| Parameters | |
|---|---|
int mediaItemIndex |
The index of the media item at which the message will be sent. |
long positionMs |
The position in the media item with index |
| Returns | |
|---|---|
PlayerMessage |
This message. |
| Throws | |
|---|---|
androidx.media3.common.IllegalSeekPositionException |
If the timeline returned by |
java.lang.IllegalStateException |
If |
setType
@CanIgnoreReturnValue
public PlayerMessage setType(int messageType)
Sets the message type forwarded to handleMessage.
| Parameters | |
|---|---|
int messageType |
The message type. |
| Returns | |
|---|---|
PlayerMessage |
This message. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If |