# 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
class PlayerMessage
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/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)( sender: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Sender!, target: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Target!, timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!, defaultMediaItemIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, clock: https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock!, defaultLooper: https://developer.android.com/reference/android/os/Looper.html! )` Creates a new message. |

| ### Public functions |
|---|---|
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/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 https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#blockUntilDelivered(long)(timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` 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/kotlin/androidx/media3/exoplayer/PlayerMessage!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#cancel()()` Cancels the message delivery. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#markAsProcessed(boolean)(isDelivered: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Marks the message as processed. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#send()()` Sends the message. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#setPosition(long)(positionMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets a position in the current media item at which the message will be delivered. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#setPosition(int,long)(mediaItemIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, positionMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets a position in a media item at which the message will be delivered. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#deleteAfterDelivery()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#isCanceled()` |
| `https://developer.android.com/reference/android/os/Looper.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#looper()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#mediaItemIndex()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#payload()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#positionMs()` |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Target!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#target()` |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#timeline()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#type()` |

## Public constructors

### PlayerMessage

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

Creates a new message.

| Parameters |
|---|---|
| `sender: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Sender!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Sender` used to send the message. |
| `target: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Target!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Target` the message is sent to. |
| `timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | The timeline used when setting the position with `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#setPosition(long)`. If set to `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline#EMPTY()`, any position can be specified. |
| `defaultMediaItemIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The default media item index in the `timeline` when no other media item index is specified. |
| `clock: https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock`. |
| `defaultLooper: https://developer.android.com/reference/android/os/Looper.html!` | The default `https://developer.android.com/reference/android/os/Looper.html` 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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#getLooper()` as it would cause a deadlock.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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/kotlin/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/kotlin/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 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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#getLooper()` as it would cause a deadlock.

| Parameters |
|---|---|
| `timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The timeout in milliseconds. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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/kotlin/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/kotlin/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 fun cancel(): PlayerMessage!
```

Cancels the message delivery.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/PlayerMessage#send()`. |

### markAsProcessed

```
synchronized fun markAsProcessed(isDelivered: Boolean): Unit
```

Marks the message as processed. Should only be called by a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage.Sender` and may be called multiple times.

| Parameters |
|---|---|
| `isDelivered: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/ExoPlaybackException` then it is propagated out of the player as an error using `https://developer.android.com/reference/kotlin/androidx/media3/common/Player.Listener#onPlayerError(androidx.media3.common.PlaybackException)`.

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

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If this message has already been sent. |

### setPosition

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

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

| Parameters |
|---|---|
| `positionMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The position in the current media item at which the message will be sent, in milliseconds, or `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/PlayerMessage!` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/PlayerMessage#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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the media item at which the message will be sent. |
| `positionMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The position in the media item with index `mediaItemIndex` at which the message will be sent, in milliseconds, or `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/PlayerMessage!` | This message. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/IllegalSeekPositionException` | If the timeline returned by `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/PlayerMessage#send()` has already been called. |

## Public properties

### deleteAfterDelivery

```
var deleteAfterDelivery: Boolean
```

### isCanceled

```
val isCanceled: Boolean
```

### looper

```
var looper: Looper!
```

### mediaItemIndex

```
val mediaItemIndex: Int
```

### payload

```
var payload: Any?
```

### positionMs

```
val positionMs: Long
```

### target

```
val target: PlayerMessage.Target!
```

### timeline

```
val timeline: Timeline!
```

### type

```
var type: Int
```