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
ADataSource
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).
getLastUri()
.
-
-
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 providedHttpDataSource
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 providedHttpDataSource
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)
-
-
-
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 usingExtendedDataSource(Context, TransferListener, String, boolean, SSLSocketFactory)
and passingtrue
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 usingExtendedDataSource(Context, TransferListener, String, boolean, SSLSocketFactory)
and passingtrue
as the final argument.- Parameters:
context
- A context.listener
- An optionalTransferListener
.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 optionalTransferListener
.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 providedHttpDataSource
for fetching remote data.- Parameters:
context
- A context.listener
- An optionalTransferListener
.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 providedHttpDataSource
for fetching remote data.- Parameters:
context
- A context.listener
- An optionalTransferListener
.httpDataSource
-DataSource
to use for non-file URIs.playerController
- The player controller
-
-
Method Detail
-
clearHeader
public void clearHeader(String name)
-
clearAllHeaders
public void clearAllHeaders()
-
getResponseHeaders
public Map<String,List<String>> getResponseHeaders()
- Specified by:
getResponseHeaders
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
getResponseCode
public int getResponseCode()
- Specified by:
getResponseCode
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
addTransferListener
public void addTransferListener(com.google.android.exoplayer2.upstream.TransferListener transferListener)
- Specified by:
addTransferListener
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
open
public long open(com.google.android.exoplayer2.upstream.DataSpec dataSpec) throws IOException
- Specified by:
open
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Throws:
IOException
-
read
public int read(byte[] buffer, int offset, int readLength) throws IOException
- Specified by:
read
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Throws:
IOException
-
getUri
public Uri getUri()
- Specified by:
getUri
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
getLastUri
public Uri getLastUri()
- Returns:
- The last accessed Uri
-
close
public void close() throws IOException
- Specified by:
close
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Throws:
IOException
-
-