# PlaybackStateEvent.Builder

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/metrics/PlaybackStateEvent.Builder "View this page in Java")  

```
class Builder
```

|---|------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                       ||
| ↳ | [android.media.metrics.PlaybackStateEvent.Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#) |

A builder for[PlaybackStateEvent](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent)

## Summary

|                                                                Public constructors                                                                 ||
|-------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#Builder())`()` Creates a new Builder. |

|                                                                                                                                                                                                                               Public methods                                                                                                                                                                                                                                ||
|--------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PlaybackStateEvent](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent)                  | [build](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#build())`()` Builds the instance.                                                                                                                                                                                                   |
| [PlaybackStateEvent.Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#) | [setMetricsBundle](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#setMetricsBundle(android.os.Bundle))`(`metricsBundle:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`)` Sets metrics-related information that is not supported by dedicated methods. |
| [PlaybackStateEvent.Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#) | [setState](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#setState(kotlin.Int))`(`value:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets playback state.                                                                                              |
| [PlaybackStateEvent.Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#) | [setTimeSinceCreatedMillis](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#setTimeSinceCreatedMillis(kotlin.Long))`(`value:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Sets timestamp since the creation in milliseconds.                           |

## Public constructors

### Builder

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder()
```

Creates a new Builder.

## Public methods

### build

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): PlaybackStateEvent
```

Builds the instance.

|                                                                   Return                                                                   ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [PlaybackStateEvent](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent) | This value cannot be`null`. |

### setMetricsBundle

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setMetricsBundle(metricsBundle: Bundle): PlaybackStateEvent.Builder
```

Sets metrics-related information that is not supported by dedicated methods.

It is intended to be used for backwards compatibility by the metrics infrastructure.

|                                                          Parameters                                                           ||
|-----------------|--------------------------------------------------------------------------------------------------------------|
| `metricsBundle` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):This value cannot be`null`. |

|                                                                           Return                                                                            ||
|--------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [PlaybackStateEvent.Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#) | This value cannot be`null`. |

### setState

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setState(value: Int): PlaybackStateEvent.Builder
```

Sets playback state.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ||
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `value` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Value is[android.media.metrics.PlaybackStateEvent#STATE_NOT_STARTED](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_NOT_STARTED:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_JOINING_BACKGROUND](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_JOINING_BACKGROUND:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_JOINING_FOREGROUND](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_JOINING_FOREGROUND:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_PLAYING](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_PLAYING:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_PAUSED](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_PAUSED:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_SEEKING](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_SEEKING:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_BUFFERING](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_BUFFERING:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_PAUSED_BUFFERING](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_PAUSED_BUFFERING:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_SUPPRESSED](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_SUPPRESSED:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_SUPPRESSED_BUFFERING](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_SUPPRESSED_BUFFERING:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_ENDED](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_ENDED:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_STOPPED](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_STOPPED:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_FAILED](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_FAILED:kotlin.Int),[android.media.metrics.PlaybackStateEvent#STATE_INTERRUPTED_BY_AD](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_INTERRUPTED_BY_AD:kotlin.Int), or[android.media.metrics.PlaybackStateEvent#STATE_ABANDONED](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#STATE_ABANDONED:kotlin.Int) |

|                                                                           Return                                                                            ||
|--------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [PlaybackStateEvent.Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#) | This value cannot be`null`. |

### setTimeSinceCreatedMillis

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setTimeSinceCreatedMillis(value: Long): PlaybackStateEvent.Builder
```

Sets timestamp since the creation in milliseconds.

|                                                                                            Parameters                                                                                             ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `value` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):the timestamp since the creation in milliseconds. -1 indicates the value is unknown. Value is -1 or greater |

|                                                                           Return                                                                            ||
|--------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [PlaybackStateEvent.Builder](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent.Builder#) | This value cannot be`null`. |

**See Also**

- [#getTimeSinceCreatedMillis()](https://developer.android.com/reference/kotlin/android/media/metrics/PlaybackStateEvent#getTimeSinceCreatedMillis())