# MediaItemStatus

# MediaItemStatus

Artifact:[androidx.mediarouter:mediarouter](https://developer.android.com/jetpack/androidx/releases/mediarouter)  
[View Source](https://cs.android.com/search?q=file:androidx/mediarouter/media/MediaItemStatus.java+class:androidx.mediarouter.media.MediaItemStatus)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/mediarouter/media/MediaItemStatus "View this page in Java")

<br />

```
class MediaItemStatus
```

<br />

*** ** * ** ***

Describes the playback status of a media item.

This class is part of the remote playback protocol described by the[MediaControlIntent](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent)class.

As a media item is played, it transitions through a sequence of states including:[pending](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PENDING()),[buffering](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_BUFFERING()),[playing](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PLAYING()),[paused](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PAUSED()),[finished](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_FINISHED()),[canceled](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_CANCELED()),[invalidated](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_INVALIDATED()), and[error](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_ERROR()). Refer to the documentation of each state for an explanation of its meaning.

While the item is playing, the playback status may also include progress information about the[content position](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#getContentPosition())and[content duration](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#getContentDuration())although not all route destinations will report it.

To monitor playback status, the application should supply a[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)to use as the[item status update receiver](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#EXTRA_ITEM_STATUS_UPDATE_RECEIVER())for a given[playback request](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_PLAY()). Note that the status update receiver will only be invoked for major status changes such as a transition from playing to finished.

The status update receiver will not be invoked for minor progress updates such as changes to playback position or duration. If the application wants to monitor playback progress, then it must use the[get status request](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_GET_STATUS())to poll for changes periodically and estimate the playback position while playing. Note that there may be a significant power impact to polling so the application is advised only to poll when the screen is on and never more than about once every 5 seconds or so.

This object is immutable once created using a[Builder](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus.Builder)instance.

## Summary

|                                                                                                                            ### Nested types                                                                                                                             |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[MediaItemStatus.Builder](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus.Builder) Builder for[media item status objects](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus). |

|                                        ### Constants                                         |
|----------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [EXTRA_HTTP_RESPONSE_HEADERS](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#EXTRA_HTTP_RESPONSE_HEADERS())` = "android.media.status.extra.HTTP_RESPONSE_HEADERS"` Bundle extra: HTTP response headers. |
| `const `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [EXTRA_HTTP_STATUS_CODE](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#EXTRA_HTTP_STATUS_CODE())` = "android.media.status.extra.HTTP_STATUS_CODE"` Integer extra: HTTP status code.                    |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_BUFFERING](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_BUFFERING())` = 3` Playback state: Buffering or seeking to a new position.                                     |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_CANCELED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_CANCELED())` = 5` Playback state: Canceled.                                                                     |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_ERROR](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_ERROR())` = 7` Playback state: Playback halted or aborted due to an error.                                         |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_FINISHED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_FINISHED())` = 4` Playback state: Finished.                                                                     |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_INVALIDATED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_INVALIDATED())` = 6` Playback state: Invalidated.                                                            |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_PAUSED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PAUSED())` = 2` Playback state: Paused.                                                                           |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_PENDING](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PENDING())` = 0` Playback state: Pending.                                                                        |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [PLAYBACK_STATE_PLAYING](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PLAYING())` = 1` Playback state: Playing.                                                                        |

|                                                     ### Public functions                                                      |
|-------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html)                                                      | [asBundle](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#asBundle())`()` Converts this object to a bundle for serialization.                                                                                                                                                                   |
| `java-static `[MediaItemStatus](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus)`?` | [fromBundle](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#fromBundle(android.os.Bundle))`(bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`?)` Creates an instance from a bundle.                                                                            |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                 | [getContentDuration](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#getContentDuration())`()` Gets the total duration of the content to be played as a long integer number of milliseconds.                                                                                                     |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                 | [getContentPosition](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#getContentPosition())`()` Gets the content playback position as a long integer number of milliseconds from the beginning of the content.                                                                                    |
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html)`?`                                                   | [getExtras](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#getExtras())`()` Gets a bundle of extras for this status object.                                                                                                                                                                     |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                   | [getPlaybackState](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#getPlaybackState())`()` Gets the playback state of the media item.                                                                                                                                                            |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                 | [getTimestamp](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#getTimestamp())`()` Gets the timestamp associated with the status information in milliseconds since boot in the[elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime())time base. |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                             | [toString](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#toString())`()`                                                                                                                                                                                                                       |

## Constants

### EXTRA_HTTP_RESPONSE_HEADERS

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val EXTRA_HTTP_RESPONSE_HEADERS = "android.media.status.extra.HTTP_RESPONSE_HEADERS": String!
```

Bundle extra: HTTP response headers.

Specifies the HTTP response headers that were returned when the content was requested from the network. The headers may include additional information about the content or any errors conditions that were encountered while trying to fetch the content.

The value is a[android.os.Bundle](https://developer.android.com/reference/android/os/Bundle.html)of string based key-value pairs that describe the HTTP response headers.  

### EXTRA_HTTP_STATUS_CODE

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val EXTRA_HTTP_STATUS_CODE = "android.media.status.extra.HTTP_STATUS_CODE": String!
```

Integer extra: HTTP status code.

Specifies the HTTP status code that was encountered when the content was requested after all redirects were followed. This key only needs to specified when the content uri uses the HTTP or HTTPS scheme and an error occurred. This key may be omitted if the content was able to be played successfully; there is no need to report a 200 (OK) status code.

The value is an integer HTTP status code, such as 401 (Unauthorized), 404 (Not Found), or 500 (Server Error), or 0 if none.  

### PLAYBACK_STATE_BUFFERING

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_BUFFERING = 3: Int
```

Playback state: Buffering or seeking to a new position.

Indicates that the media item has been temporarily interrupted to fetch more content. Playback will continue automatically when enough content has been buffered.  

### PLAYBACK_STATE_CANCELED

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_CANCELED = 5: Int
```

Playback state: Canceled.

Indicates that the media item was explicitly removed from the queue by the application. Items may be canceled and removed from the queue using the[remove](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_REMOVE())or[stop](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_STOP())action or by issuing another[play](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_PLAY())action that has the side-effect of clearing the queue.

A canceled media item cannot be resumed. To play the content again, the application must send a new[play](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_PLAY())or[enqueue](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_ENQUEUE())action.  

### PLAYBACK_STATE_ERROR

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_ERROR = 7: Int
```

Playback state: Playback halted or aborted due to an error.

Examples of errors are no network connectivity when attempting to retrieve content from a server, or expired user credentials when trying to play subscription-based content.

A media item in the error state cannot be resumed. To play the content again, the application must send a new[play](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_PLAY())or[enqueue](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_ENQUEUE())action.  

### PLAYBACK_STATE_FINISHED

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_FINISHED = 4: Int
```

Playback state: Finished.

Indicates that the media item played to the end of the content and finished normally.

A finished media item cannot be resumed. To play the content again, the application must send a new[play](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_PLAY())or[enqueue](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_ENQUEUE())action.  

### PLAYBACK_STATE_INVALIDATED

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_INVALIDATED = 6: Int
```

Playback state: Invalidated.

Indicates that the media item was invalidated permanently and involuntarily. This state is used to indicate that the media item was invalidated and removed from the queue because the session to which it belongs was invalidated (typically by another application taking control of the route).

When invalidation occurs, the application should generally wait for the user to perform an explicit action, such as clicking on a play button in the UI, before creating a new media session to avoid unnecessarily interrupting another application that may have just started using the route.

An invalidated media item cannot be resumed. To play the content again, the application must send a new[play](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_PLAY())or[enqueue](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_ENQUEUE())action.  

### PLAYBACK_STATE_PAUSED

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_PAUSED = 2: Int
```

Playback state: Paused.

Indicates that playback of the media item has been paused. Playback can be resumed using the[resume](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent#ACTION_RESUME())action.  

### PLAYBACK_STATE_PENDING

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_PENDING = 0: Int
```

Playback state: Pending.

Indicates that the media item has not yet started playback but will be played eventually.  

### PLAYBACK_STATE_PLAYING

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
const val PLAYBACK_STATE_PLAYING = 1: Int
```

Playback state: Playing.

Indicates that the media item is currently playing.  

## Public functions

### asBundle

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun asBundle(): Bundle
```

Converts this object to a bundle for serialization.  

|                                 Returns                                  |
|--------------------------------------------------------------------------|-----------------------------------------------------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html) | The contents of the object represented as a bundle. |

### fromBundle

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
java-static fun fromBundle(bundle: Bundle?): MediaItemStatus?
```

Creates an instance from a bundle.  

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|------------------------------|
| `bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`?` | The bundle, or null if none. |

|                                                     Returns                                                     |
|-----------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
| [MediaItemStatus](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus)`?` | The new instance, or null if the bundle was null. |

### getContentDuration

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun getContentDuration(): Long
```

Gets the total duration of the content to be played as a long integer number of milliseconds.  

|                                    Returns                                    |
|-------------------------------------------------------------------------------|---------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The content duration in milliseconds, or -1 if unknown. |

### getContentPosition

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun getContentPosition(): Long
```

Gets the content playback position as a long integer number of milliseconds from the beginning of the content.  

|                                    Returns                                    |
|-------------------------------------------------------------------------------|------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The content playback position in milliseconds, or -1 if unknown. |

### getExtras

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun getExtras(): Bundle?
```

Gets a bundle of extras for this status object. The extras will be ignored by the media router but they may be used by applications.  

### getPlaybackState

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun getPlaybackState(): Int
```

Gets the playback state of the media item.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The playback state. One of[PLAYBACK_STATE_PENDING](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PENDING()),[PLAYBACK_STATE_PLAYING](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PLAYING()),[PLAYBACK_STATE_PAUSED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_PAUSED()),[PLAYBACK_STATE_BUFFERING](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_BUFFERING()),[PLAYBACK_STATE_FINISHED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_FINISHED()),[PLAYBACK_STATE_CANCELED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_CANCELED()),[PLAYBACK_STATE_INVALIDATED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_INVALIDATED()), or[PLAYBACK_STATE_ERROR](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaItemStatus#PLAYBACK_STATE_ERROR()). |

### getTimestamp

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun getTimestamp(): Long
```

Gets the timestamp associated with the status information in milliseconds since boot in the[elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime())time base.  

|                                    Returns                                    |
|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The status timestamp in the[elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime())time base. |

### toString

```
fun toString(): String
```