# 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)

*** ** * ** ***


```
public interface Loader.Callback<T extends Loader.Loadable>
```

<br />

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

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

*** ** * ** ***

A callback to be notified of `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader` events.

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadCanceled(T,long,long,boolean)( T loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released )` Called when a load has been canceled. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadCompleted(T,long,long)(T loadable, long elapsedRealtimeMs, long loadDurationMs)` Called when a load has completed. |
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.LoadErrorAction` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadError(T,long,long,java.io.IOException,int)( T loadable, long elapsedRealtimeMs, long loadDurationMs, https://developer.android.com/reference/java/io/IOException.html error, int errorCount )` Called when a load encounters an error. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Callback#onLoadStarted(T,long,long,int)( T loadable, long elapsedRealtimeMs, long loadDurationMs, int retryCount )` Called when a load has started for the first time or through a retry. |

## Public methods

### onLoadCanceled

```
abstract void onLoadCanceled(
    T loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    boolean released
)
```

Called when a load has been canceled.

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

| Parameters |
|---|---|
| `T loadable` | The loadable whose load has been canceled. |
| `long elapsedRealtimeMs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the load was canceled. |
| `long loadDurationMs` | The duration in milliseconds of the load since `https://developer.android.com/reference/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. |
| `boolean released` | True if the load was canceled because the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader` was released. False otherwise. |

### onLoadCompleted

```
abstract void onLoadCompleted(T loadable, long elapsedRealtimeMs, long loadDurationMs)
```

Called when a load has completed.

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

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

### onLoadError

```
abstract Loader.LoadErrorAction onLoadError(
    T loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount
)
```

Called when a load encounters an error.

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

| Parameters |
|---|---|
| `T loadable` | The loadable whose load has encountered an error. |
| `long elapsedRealtimeMs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the error occurred. |
| `long loadDurationMs` | The duration in milliseconds of the load since `https://developer.android.com/reference/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. |
| `https://developer.android.com/reference/java/io/IOException.html error` | The load error. |
| `int errorCount` | The number of errors this load has encountered, including this one. |

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

### onLoadStarted

```
default void onLoadStarted(
    T loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    int retryCount
)
```

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 |
|---|---|
| `T loadable` | The loadable whose load has started. |
| `long elapsedRealtimeMs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the load attempts to start. |
| `long loadDurationMs` | The duration in milliseconds of the load since `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)` was called. |
| `int retryCount` | The number of failed attempts since `https://developer.android.com/reference/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). |