# PlayerMessage

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/PlayerMessage.java+class:androidx.media3.exoplayer.PlayerMessage)

*** ** * ** ***


```
@UnstableApi
public final class PlayerMessage
```

<br />

*** ** * ** ***

Defines a player message which can be sent with a `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Sender` and received by a `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target`.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Sender` A sender for messages. |
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target` A target for messages. |

| ### Public fields |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#deleteAfterDelivery()` |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#isCanceled()` |
| `https://developer.android.com/reference/android/os/Looper.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#looper()` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#mediaItemIndex()` |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#payload()` |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#positionMs()` |
| `final https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#target()` |
| `final https://developer.android.com/reference/androidx/media3/common/Timeline` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#timeline()` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#type()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#PlayerMessage(androidx.media3.exoplayer.PlayerMessage.Sender,androidx.media3.exoplayer.PlayerMessage.Target,androidx.media3.common.Timeline,int,androidx.media3.common.util.Clock,android.os.Looper)( https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Sender sender, https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target target, https://developer.android.com/reference/androidx/media3/common/Timeline timeline, int defaultMediaItemIndex, https://developer.android.com/reference/androidx/media3/common/util/Clock clock, https://developer.android.com/reference/android/os/Looper.html defaultLooper )` Creates a new message. |

| ### Public methods |
|---|---|
| `synchronized boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#blockUntilDelivered()()` Blocks until after the message has been delivered or the player is no longer able to deliver the message. |
| `synchronized boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#blockUntilDelivered(long)(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 https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#cancel()()` Cancels the message delivery. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getDeleteAfterDelivery()()` Returns whether the message will be deleted after delivery. |
| `https://developer.android.com/reference/android/os/Looper.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getLooper()()` Returns the `https://developer.android.com/reference/android/os/Looper.html` the message is delivered on. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getMediaItemIndex()()` Returns media item index at which the message will be delivered. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getPayload()()` Returns the message payload forwarded to `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`. |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getPositionMs()()` Returns position in the media item at `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getMediaItemIndex()` at which the message will be delivered, in milliseconds. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getTarget()()` Returns the target the message is sent to. |
| `https://developer.android.com/reference/androidx/media3/common/Timeline` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getTimeline()()` Returns the timeline used for setting the position with `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setPosition(long)`. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getType()()` Returns the message type forwarded to `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`. |
| `synchronized boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#isCanceled()()` Returns whether the message delivery has been canceled. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#markAsProcessed(boolean)(boolean isDelivered)` Marks the message as processed. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()()` Sends the message. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setDeleteAfterDelivery(boolean)(boolean deleteAfterDelivery)` Sets whether the message will be deleted after delivery. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setLooper(android.os.Looper)(https://developer.android.com/reference/android/os/Looper.html looper)` Sets the `https://developer.android.com/reference/android/os/Looper.html` the message is delivered on. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setPayload(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html payload)` Sets the message payload forwarded to `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setPosition(long)(long positionMs)` Sets a position in the current media item at which the message will be delivered. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setPosition(int,long)(int mediaItemIndex, long positionMs)` Sets a position in a media item at which the message will be delivered. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setType(int)(int messageType)` Sets the message type forwarded to `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`. |

## Public fields

### deleteAfterDelivery

```
public boolean deleteAfterDelivery
```

### isCanceled

```
public boolean isCanceled
```

### looper

```
public Looper looper
```

### mediaItemIndex

```
public int mediaItemIndex
```

### payload

```
public @Nullable Object payload
```

### positionMs

```
public long positionMs
```

### target

```
public final PlayerMessage.Target target
```

### timeline

```
public final Timeline timeline
```

### type

```
public int type
```

## Public constructors

### PlayerMessage

```
public PlayerMessage(
    PlayerMessage.Sender sender,
    PlayerMessage.Target target,
    Timeline timeline,
    int defaultMediaItemIndex,
    Clock clock,
    Looper defaultLooper
)
```

Creates a new message.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Sender sender` | The `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Sender` used to send the message. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target target` | The `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target` the message is sent to. |
| `https://developer.android.com/reference/androidx/media3/common/Timeline timeline` | The timeline used when setting the position with `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setPosition(long)`. If set to `https://developer.android.com/reference/androidx/media3/common/Timeline#EMPTY()`, any position can be specified. |
| `int defaultMediaItemIndex` | The default media item index in the `timeline` when no other media item index is specified. |
| `https://developer.android.com/reference/androidx/media3/common/util/Clock clock` | The `https://developer.android.com/reference/androidx/media3/common/util/Clock`. |
| `https://developer.android.com/reference/android/os/Looper.html defaultLooper` | The default `https://developer.android.com/reference/android/os/Looper.html` to send the message on when no other looper is specified. |

## 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 `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getLooper()` as it would cause a deadlock.

| Returns |
|---|---|
| `boolean` | Whether the message was delivered successfully. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called before `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()`. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called on the same thread used by the message `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getLooper()`. |
| `https://developer.android.com/reference/java/lang/InterruptedException.html` | 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 `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getLooper()` as it would cause a deadlock.

| Parameters |
|---|---|
| `long timeoutMs` | The timeout in milliseconds. |

| Returns |
|---|---|
| `boolean` | Whether the message was delivered successfully. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called before `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()`. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called on the same thread used by the message `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getLooper()`. |
| `https://developer.android.com/reference/java/util/concurrent/TimeoutException.html` | If the `timeoutMs` elapsed and this message has not been delivered and the player is still able to deliver the message. |
| `https://developer.android.com/reference/java/lang/InterruptedException.html` | 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this method is called before `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()`. |

### getDeleteAfterDelivery

```
public boolean getDeleteAfterDelivery()
```

Returns whether the message will be deleted after delivery.

### getLooper

```
public Looper getLooper()
```

Returns the `https://developer.android.com/reference/android/os/Looper.html` the message is delivered on.

### 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 `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`.

### getPositionMs

```
public long getPositionMs()
```

Returns position in the media item at `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getMediaItemIndex()` at which the message will be delivered, in milliseconds. If `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()`, the message will be delivered immediately. If `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()`, the message will be delivered at the end of the media item at `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getMediaItemIndex()`.

### getTarget

```
public PlayerMessage.Target getTarget()
```

Returns the target the message is sent to.

### getTimeline

```
public Timeline getTimeline()
```

Returns the timeline used for setting the position with `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setPosition(long)`.

### getType

```
public int getType()
```

Returns the message type forwarded to `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`.

### 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 `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.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 `isDelivered` set to true at least once. |

### send

```
@CanIgnoreReturnValue
public PlayerMessage send()
```

Sends the message. If the target throws an `https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlaybackException` then it is propagated out of the player as an error using `https://developer.android.com/reference/androidx/media3/common/Player.Listener#onPlayerError(androidx.media3.common.PlaybackException)`.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | 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 `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#setPosition(long)`.

| Parameters |
|---|---|
| `boolean deleteAfterDelivery` | Whether the message is deleted after delivery. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()` has already been called. |

### setLooper

```
@CanIgnoreReturnValue
public PlayerMessage setLooper(Looper looper)
```

Sets the `https://developer.android.com/reference/android/os/Looper.html` the message is delivered on.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Looper.html looper` | A `https://developer.android.com/reference/android/os/Looper.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()` has already been called. |

### setPayload

```
@CanIgnoreReturnValue
public PlayerMessage setPayload(@Nullable Object payload)
```

Sets the message payload forwarded to `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html payload` | The message payload. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()` has already been called. |

### 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 `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` to deliver the message at the end of the current media item. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()` has already been called. |

### 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 `mediaItemIndex` at which the message will be sent, in milliseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` to deliver the message at the end of the media item with index `mediaItemIndex`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/IllegalSeekPositionException` | If the timeline returned by `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#getTimeline()` is not empty and the provided media item index is not within the bounds of the timeline. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()` has already been called. |

### setType

```
@CanIgnoreReturnValue
public PlayerMessage setType(int messageType)
```

Sets the message type forwarded to `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage.Target#handleMessage(int,java.lang.Object)`.

| Parameters |
|---|---|
| `int messageType` | The message type. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If `https://developer.android.com/reference/androidx/media3/exoplayer/PlayerMessage#send()` has already been called. |