Package com.google.android.exoplayer2.upstream

## Class Loader

- java.lang.Object
- - com.google.android.exoplayer2.upstream.Loader

- All Implemented Interfaces:
    `LoaderErrorThrower`

      public final class Loader
      extends Object
      implements LoaderErrorThrower

  Manages the background loading of `Loader.Loadable`s.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `Loader.Callback<T extends Loader.Loadable>` | A callback to be notified of `Loader` events.
    `static interface` | `Loader.Loadable` | An object that can be loaded using a `Loader`.
    `static class` | `Loader.LoadErrorAction` | Action that can be taken in response to `Loader.Callback.onLoadError(Loadable, long, long, IOException, int)`.
    `static interface` | `Loader.ReleaseCallback` | A callback to be notified when a `Loader` has finished being released.
    `static class` | `Loader.UnexpectedLoaderException` | Thrown when an unexpected exception or error is encountered during loading.

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.upstream.LoaderErrorThrower

      `LoaderErrorThrower.Dummy`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static Loader.LoadErrorAction` | `DONT_RETRY` | Discards the failed `Loader.Loadable` and ignores any errors that have occurred.
    `static Loader.LoadErrorAction` | `DONT_RETRY_FATAL` | Discards the failed `Loader.Loadable`.
    `static Loader.LoadErrorAction` | `RETRY` | Retries the load using the default delay.
    `static Loader.LoadErrorAction` | `RETRY_RESET_ERROR_COUNT` | Retries the load using the default delay and resets the error count.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Loader​(String threadNameSuffix)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `cancelLoading()` | Cancels the current load.
    `void` | `clearFatalError()` | Clears any stored fatal error.
    `static Loader.LoadErrorAction` | `createRetryAction​(boolean resetErrorCount, long retryDelayMillis)` | Creates a `Loader.LoadErrorAction` for retrying with the given parameters.
    `boolean` | `hasFatalError()` | Whether the last call to `startLoading(T, com.google.android.exoplayer2.upstream.Loader.Callback<T>, int)` resulted in a fatal error.
    `boolean` | `isLoading()` | Returns whether the loader is currently loading.
    `void` | `maybeThrowError()` | Throws a fatal error, or a non-fatal error if loading is currently backed off and the current `Loader.Loadable` has incurred a number of errors greater than the `Loader`s default minimum number of retries.
    `void` | `maybeThrowError​(int minRetryCount)` | Throws a fatal error, or a non-fatal error if loading is currently backed off and the current `Loader.Loadable` has incurred a number of errors greater than the specified minimum number of retries.
    `void` | `release()` | Releases the loader.
    `void` | `release​(Loader.ReleaseCallback callback)` | Releases the loader.
    `<T extends Loader.Loadable> long` | `startLoading​(T loadable, Loader.Callback<T> callback, int defaultMinRetryCount)` | Starts loading a `Loader.Loadable`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### RETRY

          public static final Loader.LoadErrorAction RETRY

      Retries the load using the default delay.

    - #### RETRY_RESET_ERROR_COUNT

          public static final Loader.LoadErrorAction RETRY_RESET_ERROR_COUNT

      Retries the load using the default delay and resets the error count.

    - #### DONT_RETRY

          public static final Loader.LoadErrorAction DONT_RETRY

      Discards the failed `Loader.Loadable` and ignores any errors that have occurred.

    - #### DONT_RETRY_FATAL

          public static final Loader.LoadErrorAction DONT_RETRY_FATAL

      Discards the failed `Loader.Loadable`. The next call to `maybeThrowError()` will throw the last load error.

  - ### Constructor Detail

    - #### Loader

          public Loader​(String threadNameSuffix)

      Parameters:
        `threadNameSuffix` - A name suffix for the loader's thread. This should be the name of the component using the loader.

  - ### Method Detail

    - #### createRetryAction

          public static Loader.LoadErrorAction createRetryAction​(boolean resetErrorCount,
                                                                 long retryDelayMillis)

      Creates a `Loader.LoadErrorAction` for retrying with the given parameters.
      Parameters:
        `resetErrorCount` - Whether the previous error count should be set to zero.
        `retryDelayMillis` - The number of milliseconds to wait before retrying.
      Returns:
        A `Loader.LoadErrorAction` for retrying with the given parameters.

    - #### hasFatalError

          public boolean hasFatalError()

      Whether the last call to `startLoading(T, com.google.android.exoplayer2.upstream.Loader.Callback<T>, int)` resulted in a fatal error. Calling `maybeThrowError()` will throw the fatal error.

    - #### clearFatalError

          public void clearFatalError()

      Clears any stored fatal error.

    - #### startLoading

          public <T extends Loader.Loadable> long startLoading​(T loadable,
                                                               Loader.Callback<T> callback,
                                                               int defaultMinRetryCount)

      Starts loading a `Loader.Loadable`.

      The calling thread must be a `Looper` thread, which is the thread on which the `Loader.Callback` will be called.

      Type Parameters:
        `T` - The type of the loadable.
      Parameters:
        `loadable` - The `Loader.Loadable` to load.
        `callback` - A callback to be called when the load ends.
        `defaultMinRetryCount` - The minimum number of times the load must be retried before `maybeThrowError()` will propagate an error.
      Returns:
        `SystemClock.elapsedRealtime()` when the load started.
      Throws:
        `IllegalStateException` - If the calling thread does not have an associated `Looper`.

    - #### isLoading

          public boolean isLoading()

      Returns whether the loader is currently loading.

    - #### cancelLoading

          public void cancelLoading()

      Cancels the current load.
      Throws:
        `IllegalStateException` - If the loader is not currently loading.

    - #### release

          public void release()

      Releases the loader. This method should be called when the loader is no longer required.

    - #### release

          public void release​(@Nullable
                              Loader.ReleaseCallback callback)

      Releases the loader. This method should be called when the loader is no longer required.
      Parameters:
        `callback` - An optional callback to be called on the loading thread once the loader has been released.

    - #### maybeThrowError

          public void maybeThrowError()
                               throws IOException

      Description copied from interface: `LoaderErrorThrower`
      Throws a fatal error, or a non-fatal error if loading is currently backed off and the current `Loader.Loadable` has incurred a number of errors greater than the `Loader`s default minimum number of retries. Else does nothing.
      Specified by:
        `maybeThrowError` in interface `LoaderErrorThrower`
      Throws:
        `IOException` - The error.

    - #### maybeThrowError

          public void maybeThrowError​(int minRetryCount)
                               throws IOException

      Description copied from interface: `LoaderErrorThrower`
      Throws a fatal error, or a non-fatal error if loading is currently backed off and the current `Loader.Loadable` has incurred a number of errors greater than the specified minimum number of retries. Else does nothing.
      Specified by:
        `maybeThrowError` in interface `LoaderErrorThrower`
      Parameters:
        `minRetryCount` - A minimum retry count that must be exceeded for a non-fatal error to be thrown. Should be non-negative.
      Throws:
        `IOException` - The error.