# HlsPlaylistTracker

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

*** ** * ** ***


```
@UnstableApi
interface HlsPlaylistTracker
```

<br />

Known direct subclasses [DefaultHlsPlaylistTracker](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker` | Default implementation for `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker`. |

*** ** * ** ***

Tracks playlists associated to an HLS stream and provides snapshots.

The playlist tracker is responsible for exposing the seeking window, which is defined by the segments that one of the playlists exposes. This playlist is called primary and needs to be periodically refreshed in the case of live streams. Note that the primary playlist is one of the media playlists while the multivariant playlist is an optional kind of playlist defined by the HLS specification (RFC 8216).

Playlist loads might encounter errors. The tracker may choose to exclude them to ensure a primary playlist is always available.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.Factory` Factory for `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker` instances. |
| `interface https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PlaylistEventListener` Called on playlist loading events. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PlaylistResetException : https://developer.android.com/reference/java/io/IOException.html` Thrown when the media sequence of a new snapshot indicates the server has reset. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PlaylistStuckException : https://developer.android.com/reference/java/io/IOException.html` Thrown when a playlist is considered to be stuck due to a server side error. |
| `interface https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PrimaryPlaylistListener` Listener for primary playlist changes. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#addListener(androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker.PlaylistEventListener)(listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PlaylistEventListener!)` Registers a listener to receive events from the playlist tracker. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#deactivatePlaylistForPlayback(android.net.Uri)(url: https://developer.android.com/reference/android/net/Uri.html!)` Deactivate the playlist for playback. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#excludeMediaPlaylist(android.net.Uri,long)(playlistUrl: https://developer.android.com/reference/android/net/Uri.html!, exclusionDurationMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Excludes the given media playlist for the given duration, in milliseconds. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsContentSteeringTracker?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#getContentSteeringTracker()()` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsContentSteeringTracker`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#getInitialStartTimeUs()()` Returns the start time of the first loaded primary playlist, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET()` if no media playlist has been loaded. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsMultivariantPlaylist?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#getMultivariantPlaylist()()` Returns the multivariant playlist. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsMediaPlaylist?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#getPlaylistSnapshot(android.net.Uri,boolean)(url: https://developer.android.com/reference/android/net/Uri.html!, isForPlayback: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns the most recent snapshot available of the playlist referenced by the provided `https://developer.android.com/reference/android/net/Uri.html`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#getRedundantGroup(android.net.Uri)(playlistUrl: https://developer.android.com/reference/android/net/Uri.html!)` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup` where the `playlistUrl` belongs. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup!>?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#getRedundantGroups(int)(@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup.Type type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup` list corresponding to the `type`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#isExcluded(android.net.Uri,long)(playlistUrl: https://developer.android.com/reference/android/net/Uri.html!, nowMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Returns whether the `playlistUrl` is excluded at the given `nowMs` time. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#isExcluded(androidx.media3.exoplayer.hls.playlist.HlsRedundantGroup,long)(redundantGroup: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup!, nowMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Returns whether all playlist URLs in the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup` are `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#isExcluded(android.net.Uri,long)` at the given `nowMs` time. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#isLive()()` Returns whether the tracked playlists describe a live stream. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#isSnapshotValid(android.net.Uri)(url: https://developer.android.com/reference/android/net/Uri.html!)` Returns whether the snapshot of the playlist referenced by the provided `https://developer.android.com/reference/android/net/Uri.html` is valid, meaning all the segments referenced by the playlist are expected to be available. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#maybeThrowPlaylistRefreshError(android.net.Uri)(url: https://developer.android.com/reference/android/net/Uri.html!)` If the playlist is having trouble refreshing the playlist referenced by the given `https://developer.android.com/reference/android/net/Uri.html`, this method throws the underlying error. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#maybeThrowPrimaryPlaylistRefreshError()()` If the tracker is having trouble refreshing the multivariant playlist or the primary playlist, this method throws the underlying error. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#refreshPlaylist(android.net.Uri)(url: https://developer.android.com/reference/android/net/Uri.html!)` Requests a playlist refresh and removes it from the exclusion list. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#removeListener(androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker.PlaylistEventListener)(listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PlaylistEventListener!)` Unregisters a listener. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#start(android.net.Uri,androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher,androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker.PrimaryPlaylistListener,androidx.media3.exoplayer.upstream.BandwidthMeter)( initialPlaylistUri: https://developer.android.com/reference/android/net/Uri.html!, eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher!, primaryPlaylistListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PrimaryPlaylistListener!, bandwidthMeter: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter! )` Starts the playlist tracker. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#stop()()` Stops the playlist tracker and releases any acquired resources. |

## Public functions

### addListener

```
fun addListener(listener: HlsPlaylistTracker.PlaylistEventListener!): Unit
```

Registers a listener to receive events from the playlist tracker.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PlaylistEventListener!` | The listener. |

### deactivatePlaylistForPlayback

```
fun deactivatePlaylistForPlayback(url: Uri!): Unit
```

Deactivate the playlist for playback.

The default implementation is a no-op.

| Parameters |
|---|---|
| `url: https://developer.android.com/reference/android/net/Uri.html!` | The `https://developer.android.com/reference/android/net/Uri.html` of the playlist to deactivate for playback. |

### excludeMediaPlaylist

```
fun excludeMediaPlaylist(playlistUrl: Uri!, exclusionDurationMs: Long): Boolean
```

Excludes the given media playlist for the given duration, in milliseconds.

| Parameters |
|---|---|
| `playlistUrl: https://developer.android.com/reference/android/net/Uri.html!` | The URL of the media playlist. |
| `exclusionDurationMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The duration for which to exclude the playlist. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether exclusion was successful. |

### getContentSteeringTracker

```
fun getContentSteeringTracker(): HlsContentSteeringTracker?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsContentSteeringTracker`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsContentSteeringTracker?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/HlsContentSteeringTracker`. Null if the initial playlist has yet to be loaded, or no information for content steering is declared in the initial playlist. |

### getInitialStartTimeUs

```
fun getInitialStartTimeUs(): Long
```

Returns the start time of the first loaded primary playlist, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET()` if no media playlist has been loaded.

### getMultivariantPlaylist

```
fun getMultivariantPlaylist(): HlsMultivariantPlaylist?
```

Returns the multivariant playlist.

If the uri passed to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#start(android.net.Uri,androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher,androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker.PrimaryPlaylistListener,androidx.media3.exoplayer.upstream.BandwidthMeter)` points to a media playlist, an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsMultivariantPlaylist` with a single variant for said media playlist is returned.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsMultivariantPlaylist?` | The multivariant playlist. Null if the initial playlist has yet to be loaded. |

### getPlaylistSnapshot

```
fun getPlaylistSnapshot(url: Uri!, isForPlayback: Boolean): HlsMediaPlaylist?
```

Returns the most recent snapshot available of the playlist referenced by the provided `https://developer.android.com/reference/android/net/Uri.html`.

| Parameters |
|---|---|
| `url: https://developer.android.com/reference/android/net/Uri.html!` | The `https://developer.android.com/reference/android/net/Uri.html` corresponding to the requested media playlist. |
| `isForPlayback: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the caller might use the snapshot to request media segments for playback. If true, the primary playlist may be updated to the one requested. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsMediaPlaylist?` | The most recent snapshot of the playlist referenced by the provided `https://developer.android.com/reference/android/net/Uri.html`. May be null if no snapshot has been loaded yet. |

### getRedundantGroup

```
fun getRedundantGroup(playlistUrl: Uri!): HlsRedundantGroup?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup` where the `playlistUrl` belongs.

| Parameters |
|---|---|
| `playlistUrl: https://developer.android.com/reference/android/net/Uri.html!` | The URL of the media playlist. |

### getRedundantGroups

```
fun getRedundantGroups(@HlsRedundantGroup.Type type: Int): (Mutable)List<HlsRedundantGroup!>?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup` list corresponding to the `type`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup.Type type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type of the requested `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup`. |

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup!>?` | The list of requested `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup`. Null if the initial playlist has yet to be loaded. |

### isExcluded

```
fun isExcluded(playlistUrl: Uri!, nowMs: Long): Boolean
```

Returns whether the `playlistUrl` is excluded at the given `nowMs` time.

| Parameters |
|---|---|
| `playlistUrl: https://developer.android.com/reference/android/net/Uri.html!` | The URL of the media playlist. |
| `nowMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current value of `https://developer.android.com/reference/kotlin/androidx/media3/common/util/SystemClock#elapsedRealtime()`. |

### isExcluded

```
fun isExcluded(redundantGroup: HlsRedundantGroup!, nowMs: Long): Boolean
```

Returns whether all playlist URLs in the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup` are `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#isExcluded(android.net.Uri,long)` at the given `nowMs` time.

| Parameters |
|---|---|
| `redundantGroup: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsRedundantGroup`. |
| `nowMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current value of `https://developer.android.com/reference/kotlin/androidx/media3/common/util/SystemClock#elapsedRealtime()`. |

### isLive

```
fun isLive(): Boolean
```

Returns whether the tracked playlists describe a live stream.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | True if the content is live. False otherwise. |

### isSnapshotValid

```
fun isSnapshotValid(url: Uri!): Boolean
```

Returns whether the snapshot of the playlist referenced by the provided `https://developer.android.com/reference/android/net/Uri.html` is valid, meaning all the segments referenced by the playlist are expected to be available. If the playlist is not valid then some of the segments may no longer be available.

| Parameters |
|---|---|
| `url: https://developer.android.com/reference/android/net/Uri.html!` | The `https://developer.android.com/reference/android/net/Uri.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the snapshot of the playlist referenced by the provided `https://developer.android.com/reference/android/net/Uri.html` is valid. |

### maybeThrowPlaylistRefreshError

```
fun maybeThrowPlaylistRefreshError(url: Uri!): Unit
```

If the playlist is having trouble refreshing the playlist referenced by the given `https://developer.android.com/reference/android/net/Uri.html`, this method throws the underlying error.

| Parameters |
|---|---|
| `url: https://developer.android.com/reference/android/net/Uri.html!` | The `https://developer.android.com/reference/android/net/Uri.html`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | The underlying error. |

### maybeThrowPrimaryPlaylistRefreshError

```
fun maybeThrowPrimaryPlaylistRefreshError(): Unit
```

If the tracker is having trouble refreshing the multivariant playlist or the primary playlist, this method throws the underlying error. Otherwise, does nothing.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | The underlying error. |

### refreshPlaylist

```
fun refreshPlaylist(url: Uri!): Unit
```

Requests a playlist refresh and removes it from the exclusion list.

The playlist tracker may choose to delay the playlist refresh. The request is discarded if a refresh was already pending.

| Parameters |
|---|---|
| `url: https://developer.android.com/reference/android/net/Uri.html!` | The `https://developer.android.com/reference/android/net/Uri.html` of the playlist to be refreshed. |

### removeListener

```
fun removeListener(listener: HlsPlaylistTracker.PlaylistEventListener!): Unit
```

Unregisters a listener.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PlaylistEventListener!` | The listener to unregister. |

### start

```
fun start(
    initialPlaylistUri: Uri!,
    eventDispatcher: MediaSourceEventListener.EventDispatcher!,
    primaryPlaylistListener: HlsPlaylistTracker.PrimaryPlaylistListener!,
    bandwidthMeter: BandwidthMeter!
): Unit
```

Starts the playlist tracker.

Must be called from the playback thread. A tracker may be restarted after a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#stop()` call.

| Parameters |
|---|---|
| `initialPlaylistUri: https://developer.android.com/reference/android/net/Uri.html!` | Uri of the HLS stream. Can point to a media playlist or a multivariant playlist. |
| `eventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher!` | A dispatcher to notify of events. |
| `primaryPlaylistListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker.PrimaryPlaylistListener!` | A callback for the primary playlist change events. |
| `bandwidthMeter: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter`. |

### stop

```
fun stop(): Unit
```

Stops the playlist tracker and releases any acquired resources.

Must be called once per `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker#start(android.net.Uri,androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher,androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker.PrimaryPlaylistListener,androidx.media3.exoplayer.upstream.BandwidthMeter)` call.