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
ConstructorsConstructorDescriptionExtendedDataSource(Context context, com.google.android.exoplayer2.upstream.TransferListener listener, com.google.android.exoplayer2.upstream.HttpDataSource httpDataSource) Constructs a new instance, using a providedHttpDataSourcefor 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 providedHttpDataSourcefor 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 TypeMethodDescriptionvoidaddTransferListener(com.google.android.exoplayer2.upstream.TransferListener transferListener) voidvoidclearHeader(String name) voidclose()Returns the last accessed Uri.intgetUri()longopen(com.google.android.exoplayer2.upstream.DataSpec dataSpec) intread(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 passingtrueas 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 passingtrueas 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.sslSocketFactory- The SSL socket factory to use for HTTPS connections
-
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 providedHttpDataSourcefor fetching remote data.- Parameters:
context- A context.listener- An optionalTransferListener.httpDataSource-DataSourceto 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 providedHttpDataSourcefor fetching remote data.- Parameters:
context- A context.listener- An optionalTransferListener.httpDataSource-DataSourceto use for non-file URIs.playerController- The player controller
-
-
Method Details
-
setHeader
-
clearHeader
-
clearAllHeaders
public void clearAllHeaders() -
getResponseHeaders
- Specified by:
getResponseHeadersin interfacecom.google.android.exoplayer2.upstream.DataSource
-
getResponseCode
public int getResponseCode()- Specified by:
getResponseCodein interfacecom.google.android.exoplayer2.upstream.DataSource
-
addTransferListener
public void addTransferListener(com.google.android.exoplayer2.upstream.TransferListener transferListener) - Specified by:
addTransferListenerin interfacecom.google.android.exoplayer2.upstream.DataSource
-
open
- Specified by:
openin interfacecom.google.android.exoplayer2.upstream.DataSource- Throws:
IOException
-
read
- Specified by:
readin interfacecom.google.android.exoplayer2.upstream.DataSource- Throws:
IOException
-
getUri
- Specified by:
getUriin interfacecom.google.android.exoplayer2.upstream.DataSource
-
getLastUri
Returns the last accessed Uri.- Returns:
- The last accessed Uri
-
close
- Specified by:
closein interfacecom.google.android.exoplayer2.upstream.DataSource- Throws:
IOException
-