# TimeBar

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

*** ** * ** ***

<br />

```
@UnstableApi
interface TimeBar
```

<br />

Known direct subclasses [DefaultTimeBar](https://developer.android.com/reference/kotlin/androidx/media3/ui/DefaultTimeBar)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/ui/DefaultTimeBar` | A time bar that shows a current position, buffered position, duration and ad markers. |

*** ** * ** ***

Interface for time bar views that can display a playback position, buffered position, duration and ad markers, and that have a listener for scrubbing (seeking) events.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar.OnScrubListener` Listener for scrubbing events. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#addListener(androidx.media3.ui.TimeBar.OnScrubListener)(listener: https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar.OnScrubListener!)` Adds a listener for scrubbing events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#getPreferredUpdateDelay()()` Returns the preferred delay in milliseconds of media time after which the time bar position should be updated. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#removeListener(androidx.media3.ui.TimeBar.OnScrubListener)(listener: https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar.OnScrubListener!)` Removes a listener for scrubbing events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setAdGroupTimesMs(long[],boolean[],int)( adGroupTimesMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>?, playedAdGroups: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html>?, adGroupCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Sets the times of ad groups and whether each ad group has been played. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setBufferedPosition(long)(bufferedPosition: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets the buffered position. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setDuration(long)(duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets the duration. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setEnabled(boolean)(enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setKeyCountIncrement(int)(count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the position increment for key presses and accessibility actions, as a number of increments that divide the duration of the media. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setKeyTimeIncrement(long)(time: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets the position increment for key presses and accessibility actions, in milliseconds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setPosition(long)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets the current position. |

## Public functions

### addListener

```
fun addListener(listener: TimeBar.OnScrubListener!): Unit
```

Adds a listener for scrubbing events.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar.OnScrubListener!` | The listener to add. |

### getPreferredUpdateDelay

```
fun getPreferredUpdateDelay(): Long
```

Returns the preferred delay in milliseconds of media time after which the time bar position should be updated.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | Preferred delay, in milliseconds of media time. |

### removeListener

```
fun removeListener(listener: TimeBar.OnScrubListener!): Unit
```

Removes a listener for scrubbing events.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar.OnScrubListener!` | The listener to remove. |

### setAdGroupTimesMs

```
fun setAdGroupTimesMs(
    adGroupTimesMs: LongArray<Long>?,
    playedAdGroups: BooleanArray<Boolean>?,
    adGroupCount: Int
): Unit
```

Sets the times of ad groups and whether each ad group has been played.

| Parameters |
|---|---|
| `adGroupTimesMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>?` | An array where the first `adGroupCount` elements are the times of ad groups in milliseconds. May be `null` if there are no ad groups. |
| `playedAdGroups: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html>?` | An array where the first `adGroupCount` elements indicate whether the corresponding ad groups have been played. May be `null` if there are no ad groups. |
| `adGroupCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of ad groups. |

### setBufferedPosition

```
fun setBufferedPosition(bufferedPosition: Long): Unit
```

Sets the buffered position.

| Parameters |
|---|---|
| `bufferedPosition: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current buffered position to show, in milliseconds. |

### setDuration

```
fun setDuration(duration: Long): Unit
```

Sets the duration.

| Parameters |
|---|---|
| `duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The duration to show, in milliseconds. |

### setEnabled

```
fun setEnabled(enabled: Boolean): Unit
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/View.html#isEnabled()` |   |

### setKeyCountIncrement

```
fun setKeyCountIncrement(count: Int): Unit
```

Sets the position increment for key presses and accessibility actions, as a number of increments that divide the duration of the media. For example, passing 20 will cause key presses to increment/decrement the position by 1/20th of the duration (if known).

Clears any increment specified in a preceding call to `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setKeyTimeIncrement(long)`.

| Parameters |
|---|---|
| `count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of increments that divide the duration of the media. |

### setKeyTimeIncrement

```
fun setKeyTimeIncrement(time: Long): Unit
```

Sets the position increment for key presses and accessibility actions, in milliseconds.

Clears any increment specified in a preceding call to `https://developer.android.com/reference/kotlin/androidx/media3/ui/TimeBar#setKeyCountIncrement(int)`.

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

### setPosition

```
fun setPosition(position: Long): Unit
```

Sets the current position.

| Parameters |
|---|---|
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current position to show, in milliseconds. |