Package com.google.android.exoplayer2.upstream

## Class BaseDataSource

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

- All Implemented Interfaces:
    `DataReader`, `DataSource`
  Direct Known Subclasses:
    `AssetDataSource`, `ByteArrayDataSource`, `ContentDataSource`, `CronetDataSource`, `DataSchemeDataSource`, `DefaultHttpDataSource`, `FakeDataSource`, `FileDataSource`, `OkHttpDataSource`, `RawResourceDataSource`, `RtmpDataSource`, `UdpDataSource`

      public abstract class BaseDataSource
      extends Object
      implements DataSource

  Base `DataSource` implementation to keep a list of `TransferListener`s.

  Subclasses must call `transferInitializing(DataSpec)`, `transferStarted(DataSpec)`, `bytesTransferred(int)`, and `transferEnded()` to inform listeners of data transfers.

- - ### Nested Class Summary

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

      `DataSource.Factory`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `BaseDataSource​(boolean isNetwork)` | Creates base data source.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addTransferListener​(TransferListener transferListener)` | Adds a `TransferListener` to listen to data transfers.
    `protected void` | `bytesTransferred​(int bytesTransferred)` | Notifies listeners that bytes were transferred.
    `protected void` | `transferEnded()` | Notifies listeners that a transfer ended.
    `protected void` | `transferInitializing​(DataSpec dataSpec)` | Notifies listeners that data transfer for the specified `DataSpec` is being initialized.
    `protected void` | `transferStarted​(DataSpec dataSpec)` | Notifies listeners that data transfer for the specified `DataSpec` started.

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

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

    - ### Methods inherited from interface com.google.android.exoplayer2.upstream.DataReader

      `read`

    - ### Methods inherited from interface com.google.android.exoplayer2.upstream.DataSource

      `close, getResponseHeaders, getUri, open`

- - ### Constructor Detail

    - #### BaseDataSource

          protected BaseDataSource​(boolean isNetwork)

      Creates base data source.
      Parameters:
        `isNetwork` - Whether the data source loads data through a network.

  - ### Method Detail

    - #### addTransferListener

          public final void addTransferListener​(TransferListener transferListener)

      Description copied from interface: `DataSource`
      Adds a `TransferListener` to listen to data transfers. This method is not thread-safe.
      Specified by:
        `addTransferListener` in interface `DataSource`
      Parameters:
        `transferListener` - A `TransferListener`.

    - #### transferInitializing

          protected final void transferInitializing​(DataSpec dataSpec)

      Notifies listeners that data transfer for the specified `DataSpec` is being initialized.
      Parameters:
        `dataSpec` - `DataSpec` describing the data for initializing transfer.

    - #### transferStarted

          protected final void transferStarted​(DataSpec dataSpec)

      Notifies listeners that data transfer for the specified `DataSpec` started.
      Parameters:
        `dataSpec` - `DataSpec` describing the data being transferred.

    - #### bytesTransferred

          protected final void bytesTransferred​(int bytesTransferred)

      Notifies listeners that bytes were transferred.
      Parameters:
        `bytesTransferred` - The number of bytes transferred since the previous call to this method (or if the first call, since the transfer was started).

    - #### transferEnded

          protected final void transferEnded()

      Notifies listeners that a transfer ended.