# Loader.Callback

# Loader.Callback

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/upstream/Loader.java+class:androidx.media3.exoplayer.upstream.Loader.Callback)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Callback "View this page in Java")


```
interface Loader.Callback<T : Loader.Loadable?>
```

<br />

Known direct subclasses  
[ChunkSampleStream](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream), [DefaultHlsPlaylistTracker](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker), [SsMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/smoothstreaming/SsMediaSource)  

|----------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ChunkSampleStream](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream)                 | A [SampleStream](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream) that loads media in [Chunk](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk)s, obtained from a [ChunkSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSource). |
| [DefaultHlsPlaylistTracker](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker) | Default implementation for [HlsPlaylistTracker](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/hls/playlist/HlsPlaylistTracker).                                                                                                                                                                                                                  |
| [SsMediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/smoothstreaming/SsMediaSource)                      | A SmoothStreaming [MediaSource](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource).                                                                                                                                                                                                                                               |

*** ** * ** ***

A callback to be notified of [Loader](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader) events.

## Summary

|                                                         ### Public functions                                                          |
|---------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                         | [onLoadCanceled](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadCanceled(T,long,long,boolean))`(` ` loadable: T!,` ` elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` released: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) `)` Called when a load has been canceled.                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                         | [onLoadCompleted](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadCompleted(T,long,long))`(loadable: T!, elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Called when a load has completed.                                                                                                                                                                                                                              |
| [Loader.LoadErrorAction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.LoadErrorAction)`!` | [onLoadError](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadError(T,long,long,java.io.IOException,int))`(` ` loadable: T!,` ` elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` error: `[IOException](https://developer.android.com/reference/java/io/IOException.html)`!,` ` errorCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Called when a load encounters an error. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                         | [onLoadStarted](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadStarted(T,long,long,int))`(` ` loadable: T!,` ` elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` retryCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Called when a load has started for the first time or through a retry.                                                                                 |

## Public functions

### onLoadCanceled

```
fun onLoadCanceled(
    loadable: T!,
    elapsedRealtimeMs: Long,
    loadDurationMs: Long,
    released: Boolean
): Unit
```

Called when a load has been canceled.

Note: If the [Loader](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader) has not been released then there is guaranteed to be a memory barrier between [load](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Loadable#load()) exiting and this callback being called. If the [Loader](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader) has been released then this callback may be called before [load](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Loadable#load()) exits.  

|                                             Parameters                                             |
|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `loadable: T!`                                                                                     | The loadable whose load has been canceled.                                                                                                                                                                                                                                             |
| `elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()) when the load was canceled.                                                                                                                                                   |
| `loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)    | The duration in milliseconds of the load since [startLoading](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)) was called up to the point at which it was canceled. |
| `released: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)    | True if the load was canceled because the [Loader](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader) was released. False otherwise.                                                                                                            |

### onLoadCompleted

```
fun onLoadCompleted(loadable: T!, elapsedRealtimeMs: Long, loadDurationMs: Long): Unit
```

Called when a load has completed.

Note: There is guaranteed to be a memory barrier between [load](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Loadable#load()) exiting and this callback being called.  

|                                             Parameters                                             |
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `loadable: T!`                                                                                     | The loadable whose load has completed.                                                                                                                                                                                                        |
| `elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()) when the load ended.                                                                                                                 |
| `loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)    | The duration in milliseconds of the load since [startLoading](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)) was called. |

### onLoadError

```
fun onLoadError(
    loadable: T!,
    elapsedRealtimeMs: Long,
    loadDurationMs: Long,
    error: IOException!,
    errorCount: Int
): Loader.LoadErrorAction!
```

Called when a load encounters an error.

Note: There is guaranteed to be a memory barrier between [load](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.Loadable#load()) exiting and this callback being called.  

|                                             Parameters                                             |
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `loadable: T!`                                                                                     | The loadable whose load has encountered an error.                                                                                                                                                                                                                                         |
| `elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()) when the error occurred.                                                                                                                                                         |
| `loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)    | The duration in milliseconds of the load since [startLoading](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)) was called up to the point at which the error occurred. |
| `error: `[IOException](https://developer.android.com/reference/java/io/IOException.html)`!`        | The load error.                                                                                                                                                                                                                                                                           |
| `errorCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | The number of errors this load has encountered, including this one.                                                                                                                                                                                                                       |

|                                                                Returns                                                                |
|---------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Loader.LoadErrorAction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader.LoadErrorAction)`!` | The desired error handling action. One of [RETRY](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#RETRY()), [RETRY_RESET_ERROR_COUNT](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#RETRY_RESET_ERROR_COUNT()), [DONT_RETRY](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#DONT_RETRY()), [DONT_RETRY_FATAL](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#DONT_RETRY_FATAL()) or a retry action created by [createRetryAction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#createRetryAction(boolean,long)). |

### onLoadStarted

```
fun onLoadStarted(
    loadable: T!,
    elapsedRealtimeMs: Long,
    loadDurationMs: Long,
    retryCount: Int
): Unit
```

Called when a load has started for the first time or through a retry.

This is called for the first time with `retryCount == 0` just **before** the load is started.  

|                                             Parameters                                             |
|----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `loadable: T!`                                                                                     | The loadable whose load has started.                                                                                                                                                                                                                                         |
| `elapsedRealtimeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()) when the load attempts to start.                                                                                                                                    |
| `loadDurationMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)    | The duration in milliseconds of the load since [startLoading](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)) was called.                                |
| `retryCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | The number of failed attempts since [startLoading](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)) was called (this is zero for the first load attempt). |