Package com.castlabs.android.network

## Class ExtendedDataSource

- java.lang.Object
- - com.castlabs.android.network.ExtendedDataSource

- All Implemented Interfaces:
    `com.google.android.exoplayer2.upstream.DataSource`

      public class ExtendedDataSource
      extends Object
      implements com.google.android.exoplayer2.upstream.DataSource

  A `DataSource` that supports multiple URI schemes. The supported schemes are:

  - http(s): For fetching data over HTTP and HTTPS (e.g. https://www.something.com/media.mp4).
  - file: For fetching data from a local file (e.g. file:///path/to/media/media.mp4, or just /path/to/media/media.mp4 because the implementation assumes that a URI without a scheme is a local file URI).
  - asset: For fetching data from an asset in the application's apk (e.g. asset:///media.mp4).
  - content: For fetching data from a content URI (e.g. content://authority/path/123).
  Instances of this class also expose the last accessed Uri using `getLastUri()`.

- - ### Nested Class Summary

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

      `com.google.android.exoplayer2.upstream.DataSource.Factory`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ExtendedDataSource​(Context context, com.google.android.exoplayer2.upstream.TransferListener listener, com.google.android.exoplayer2.upstream.HttpDataSource httpDataSource)` | Constructs a new instance, using a provided `HttpDataSource` for fetching remote data.
    `ExtendedDataSource​(Context context, com.google.android.exoplayer2.upstream.TransferListener listener, com.google.android.exoplayer2.upstream.HttpDataSource httpDataSource, PlayerController playerController)` | Constructs a new instance, using a provided `HttpDataSource` for fetching remote data.
    `ExtendedDataSource​(Context context, com.google.android.exoplayer2.upstream.TransferListener listener, String userAgent)` | Constructs a new instance.
    `ExtendedDataSource​(Context context, com.google.android.exoplayer2.upstream.TransferListener listener, String userAgent, boolean allowCrossProtocolRedirects, SSLSocketFactory sslSocketFactory)` | Constructs a new instance, optionally configured to follow cross-protocol redirects.
    `ExtendedDataSource​(Context context, String userAgent)` | Constructs a new instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addTransferListener​(com.google.android.exoplayer2.upstream.TransferListener transferListener)` |
    `void` | `clearAllHeaders()` |
    `void` | `clearHeader​(String name)` |
    `void` | `close()` |
    `Uri` | `getLastUri()` |
    `int` | `getResponseCode()` |
    `Map<String,​List<String>>` | `getResponseHeaders()` |
    `Uri` | `getUri()` |
    `long` | `open​(com.google.android.exoplayer2.upstream.DataSpec dataSpec)` |
    `int` | `read​(byte[] buffer, int offset, int readLength)` |
    `void` | `setHeader​(String name, String value)` |

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

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

- - ### Constructor Detail

    - #### ExtendedDataSource

          public ExtendedDataSource​(Context context,
                                    String userAgent)

      Constructs a new instance.

      The constructed instance will not follow cross-protocol redirects (i.e. redirects from HTTP to HTTPS or vice versa) when fetching remote data. Cross-protocol redirects can be enabled by using `ExtendedDataSource(Context, TransferListener, String, boolean, SSLSocketFactory)` and passing `true` as the final argument.
      Parameters:
        `context` - A context.
        `userAgent` - The User-Agent string that should be used when requesting remote data.

    - #### ExtendedDataSource

          public ExtendedDataSource​(Context context,
                                    com.google.android.exoplayer2.upstream.TransferListener listener,
                                    String userAgent)

      Constructs a new instance.

      The constructed instance will not follow cross-protocol redirects (i.e. redirects from HTTP to HTTPS or vice versa) when fetching remote data. Cross-protocol redirects can be enabled by using `ExtendedDataSource(Context, TransferListener, String, boolean, SSLSocketFactory)` and passing `true` as the final argument.
      Parameters:
        `context` - A context.
        `listener` - An optional `TransferListener`.
        `userAgent` - The User-Agent string that should be used when requesting remote data.

    - #### ExtendedDataSource

          public ExtendedDataSource​(Context context,
                                    com.google.android.exoplayer2.upstream.TransferListener listener,
                                    String userAgent,
                                    boolean allowCrossProtocolRedirects,
                                    @Nullable
                                    SSLSocketFactory sslSocketFactory)

      Constructs a new instance, optionally configured to follow cross-protocol redirects.
      Parameters:
        `context` - A context.
        `listener` - An optional `TransferListener`.
        `userAgent` - The User-Agent string that should be used when requesting remote data.
        `allowCrossProtocolRedirects` - Whether cross-protocol redirects (i.e. redirects from HTTP to HTTPS and vice versa) are enabled when fetching remote data..

    - #### ExtendedDataSource

          public ExtendedDataSource​(Context context,
                                    com.google.android.exoplayer2.upstream.TransferListener listener,
                                    com.google.android.exoplayer2.upstream.HttpDataSource httpDataSource)

      Constructs a new instance, using a provided `HttpDataSource` for fetching remote data.
      Parameters:
        `context` - A context.
        `listener` - An optional `TransferListener`.
        `httpDataSource` - `DataSource` to use for non-file URIs.

    - #### ExtendedDataSource

          public ExtendedDataSource​(Context context,
                                    com.google.android.exoplayer2.upstream.TransferListener listener,
                                    com.google.android.exoplayer2.upstream.HttpDataSource httpDataSource,
                                    @Nullable
                                    PlayerController playerController)

      Constructs a new instance, using a provided `HttpDataSource` for fetching remote data.
      Parameters:
        `context` - A context.
        `listener` - An optional `TransferListener`.
        `httpDataSource` - `DataSource` to use for non-file URIs.
        `playerController` - The player controller

  - ### Method Detail

    - #### setHeader

          public void setHeader​(String name,
                                String value)

    - #### clearHeader

          public void clearHeader​(String name)

    - #### clearAllHeaders

          public void clearAllHeaders()

    - #### getResponseHeaders

          public Map<String,​List<String>> getResponseHeaders()

      Specified by:
        `getResponseHeaders` in interface `com.google.android.exoplayer2.upstream.DataSource`

    - #### getResponseCode

          public int getResponseCode()

      Specified by:
        `getResponseCode` in interface `com.google.android.exoplayer2.upstream.DataSource`

    - #### addTransferListener

          public void addTransferListener​(com.google.android.exoplayer2.upstream.TransferListener transferListener)

      Specified by:
        `addTransferListener` in interface `com.google.android.exoplayer2.upstream.DataSource`

    - #### open

          public long open​(com.google.android.exoplayer2.upstream.DataSpec dataSpec)
                    throws IOException

      Specified by:
        `open` in interface `com.google.android.exoplayer2.upstream.DataSource`
      Throws:
        `IOException`

    - #### read

          public int read​(byte[] buffer,
                          int offset,
                          int readLength)
                   throws IOException

      Specified by:
        `read` in interface `com.google.android.exoplayer2.upstream.DataSource`
      Throws:
        `IOException`

    - #### getUri

          public Uri getUri()

      Specified by:
        `getUri` in interface `com.google.android.exoplayer2.upstream.DataSource`

    - #### getLastUri

          public Uri getLastUri()

      Returns:
        The last accessed Uri

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `com.google.android.exoplayer2.upstream.DataSource`
      Throws:
        `IOException`