Class ExtendedDataSource

java.lang.Object
com.castlabs.android.network.ExtendedDataSource
All Implemented Interfaces:
com.castlabs.media3.common.DataReader, com.castlabs.media3.datasource.DataSource

public class ExtendedDataSource extends Object implements com.castlabs.media3.datasource.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().
  • Constructor Details

    • 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.castlabs.media3.datasource.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.castlabs.media3.datasource.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.
      sslSocketFactory - The SSL socket factory to use for HTTPS connections
    • ExtendedDataSource

      public ExtendedDataSource(Context context, com.castlabs.media3.datasource.TransferListener listener, com.castlabs.media3.datasource.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.castlabs.media3.datasource.TransferListener listener, com.castlabs.media3.datasource.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 Details

    • 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.castlabs.media3.datasource.DataSource
    • getResponseCode

      public int getResponseCode()
      Specified by:
      getResponseCode in interface com.castlabs.media3.datasource.DataSource
    • addTransferListener

      public void addTransferListener(com.castlabs.media3.datasource.TransferListener transferListener)
      Specified by:
      addTransferListener in interface com.castlabs.media3.datasource.DataSource
    • open

      public long open(com.castlabs.media3.datasource.DataSpec dataSpec) throws IOException
      Specified by:
      open in interface com.castlabs.media3.datasource.DataSource
      Throws:
      IOException
    • read

      public int read(byte[] buffer, int offset, int readLength) throws IOException
      Specified by:
      read in interface com.castlabs.media3.common.DataReader
      Throws:
      IOException
    • getUri

      public Uri getUri()
      Specified by:
      getUri in interface com.castlabs.media3.datasource.DataSource
    • getLastUri

      public Uri getLastUri()
      Returns the last accessed Uri.
      Returns:
      The last accessed Uri
    • close

      public void close() throws IOException
      Specified by:
      close in interface com.castlabs.media3.datasource.DataSource
      Throws:
      IOException