public final class PlayerMessage extends Object
PlayerMessage.Sender
and received by a PlayerMessage.Target
.Modifier and Type | Class | Description |
---|---|---|
static interface |
PlayerMessage.Sender |
A sender for messages.
|
static interface |
PlayerMessage.Target |
A target for messages.
|
Constructor | Description |
---|---|
PlayerMessage(PlayerMessage.Sender sender,
PlayerMessage.Target target,
Timeline timeline,
int defaultWindowIndex,
Clock clock,
Looper defaultLooper) |
Creates a new message.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
blockUntilDelivered() |
Blocks until after the message has been delivered or the player is no longer able to deliver
the message.
|
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.
|
PlayerMessage |
cancel() |
Cancels the message delivery.
|
boolean |
getDeleteAfterDelivery() |
Returns whether the message will be deleted after delivery.
|
Looper |
getLooper() |
Returns the
Looper the message is delivered on. |
Object |
getPayload() |
Returns the message payload forwarded to
PlayerMessage.Target.handleMessage(int, Object) . |
long |
getPositionMs() |
Returns position in window at
getWindowIndex() at which the message will be delivered,
in milliseconds. |
PlayerMessage.Target |
getTarget() |
Returns the target the message is sent to.
|
Timeline |
getTimeline() |
Returns the timeline used for setting the position with
setPosition(long) . |
int |
getType() |
Returns the message type forwarded to
PlayerMessage.Target.handleMessage(int, Object) . |
int |
getWindowIndex() |
Returns window index at which the message will be delivered.
|
boolean |
isCanceled() |
Returns whether the message delivery has been canceled.
|
void |
markAsProcessed(boolean isDelivered) |
Marks the message as processed.
|
PlayerMessage |
send() |
Sends the message.
|
PlayerMessage |
setDeleteAfterDelivery(boolean deleteAfterDelivery) |
Sets whether the message will be deleted after delivery.
|
PlayerMessage |
setHandler(Handler handler) |
Deprecated.
Use
setLooper(Looper) instead. |
PlayerMessage |
setLooper(Looper looper) |
Sets the
Looper the message is delivered on. |
PlayerMessage |
setPayload(Object payload) |
Sets the message payload forwarded to
PlayerMessage.Target.handleMessage(int, Object) . |
PlayerMessage |
setPosition(int windowIndex,
long positionMs) |
Sets a position in a window at which the message will be delivered.
|
PlayerMessage |
setPosition(long positionMs) |
Sets a position in the current window at which the message will be delivered.
|
PlayerMessage |
setType(int messageType) |
Sets the message type forwarded to
PlayerMessage.Target.handleMessage(int, Object) . |
public PlayerMessage(PlayerMessage.Sender sender, PlayerMessage.Target target, Timeline timeline, int defaultWindowIndex, Clock clock, Looper defaultLooper)
sender
- The PlayerMessage.Sender
used to send the message.target
- The PlayerMessage.Target
the message is sent to.timeline
- The timeline used when setting the position with setPosition(long)
. If
set to Timeline.EMPTY
, any position can be specified.defaultWindowIndex
- The default window index in the timeline
when no other window
index is specified.clock
- The Clock
.defaultLooper
- The default Looper
to send the message on when no other looper is
specified.public Timeline getTimeline()
setPosition(long)
.public PlayerMessage.Target getTarget()
public PlayerMessage setType(int messageType)
PlayerMessage.Target.handleMessage(int, Object)
.messageType
- The message type.IllegalStateException
- If send()
has already been called.public int getType()
PlayerMessage.Target.handleMessage(int, Object)
.public PlayerMessage setPayload(@Nullable Object payload)
PlayerMessage.Target.handleMessage(int, Object)
.payload
- The message payload.IllegalStateException
- If send()
has already been called.@Nullable public Object getPayload()
PlayerMessage.Target.handleMessage(int, Object)
.@Deprecated public PlayerMessage setHandler(Handler handler)
setLooper(Looper)
instead.public PlayerMessage setLooper(Looper looper)
Looper
the message is delivered on.looper
- A Looper
.IllegalStateException
- If send()
has already been called.public long getPositionMs()
getWindowIndex()
at which the message will be delivered,
in milliseconds. If C.TIME_UNSET
, the message will be delivered immediately. If C.TIME_END_OF_SOURCE
, the message will be delivered at the end of the window at getWindowIndex()
.public PlayerMessage setPosition(long positionMs)
positionMs
- The position in the current window at which the message will be sent, in
milliseconds, or C.TIME_END_OF_SOURCE
to deliver the message at the end of the
current window.IllegalStateException
- If send()
has already been called.public PlayerMessage setPosition(int windowIndex, long positionMs)
windowIndex
- The index of the window at which the message will be sent.positionMs
- The position in the window with index windowIndex
at which the
message will be sent, in milliseconds, or C.TIME_END_OF_SOURCE
to deliver the
message at the end of the window with index windowIndex
.IllegalSeekPositionException
- If the timeline returned by getTimeline()
is not
empty and the provided window index is not within the bounds of the timeline.IllegalStateException
- If send()
has already been called.public int getWindowIndex()
public PlayerMessage setDeleteAfterDelivery(boolean deleteAfterDelivery)
setPosition(long)
.deleteAfterDelivery
- Whether the message is deleted after delivery.IllegalStateException
- If send()
has already been called.public boolean getDeleteAfterDelivery()
public PlayerMessage send()
ExoPlaybackException
then it is propagated
out of the player as an error using Player.EventListener.onPlayerError(ExoPlaybackException)
.IllegalStateException
- If this message has already been sent.public PlayerMessage cancel()
IllegalStateException
- If this method is called before send()
.public boolean isCanceled()
public void markAsProcessed(boolean isDelivered)
PlayerMessage.Sender
and may be called
multiple times.isDelivered
- 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.public boolean blockUntilDelivered() throws InterruptedException
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.
IllegalStateException
- If this method is called before send()
.IllegalStateException
- If this method is called on the same thread used by the message
looper
.InterruptedException
- If the current thread is interrupted while waiting for the message
to be delivered.public boolean blockUntilDelivered(long timeoutMs) throws InterruptedException, TimeoutException
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.
timeoutMs
- The timeout in milliseconds.IllegalStateException
- If this method is called before send()
.IllegalStateException
- If this method is called on the same thread used by the message
looper
.TimeoutException
- If the timeoutMs
elapsed and this message has not been
delivered and the player is still able to deliver the message.InterruptedException
- If the current thread is interrupted while waiting for the message
to be delivered.