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).
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
ConstructorDescriptionExtendedDataSource
(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
Modifier and TypeMethodDescriptionvoid
addTransferListener
(com.google.android.exoplayer2.upstream.TransferListener transferListener) void
void
clearHeader
(String name) void
close()
int
getUri()
long
open
(com.google.android.exoplayer2.upstream.DataSpec dataSpec) int
read
(byte[] buffer, int offset, int readLength) void
-
Constructor Details
-
ExtendedDataSource
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 Details
-
setHeader
-
clearHeader
-
clearAllHeaders
public void clearAllHeaders() -
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
- Specified by:
open
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Throws:
IOException
-
read
- Specified by:
read
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Throws:
IOException
-
getUri
- Specified by:
getUri
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
getLastUri
- Returns:
- The last accessed Uri
-
close
- Specified by:
close
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Throws:
IOException
-