public class OkHttpDataSource
extends java.lang.Object
implements com.google.android.exoplayer2.upstream.HttpDataSource
HttpDataSource that delegates to Square's Call.Factory.com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory, com.google.android.exoplayer2.upstream.HttpDataSource.Factory, com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException, com.google.android.exoplayer2.upstream.HttpDataSource.InvalidContentTypeException, com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException, com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties| Constructor and Description |
|---|
OkHttpDataSource(okhttp3.Call.Factory callFactory,
java.lang.String userAgent,
com.google.android.exoplayer2.util.Predicate<java.lang.String> contentTypePredicate) |
OkHttpDataSource(okhttp3.Call.Factory callFactory,
java.lang.String userAgent,
com.google.android.exoplayer2.util.Predicate<java.lang.String> contentTypePredicate,
com.google.android.exoplayer2.upstream.TransferListener<? super OkHttpDataSource> listener) |
OkHttpDataSource(okhttp3.Call.Factory callFactory,
java.lang.String userAgent,
com.google.android.exoplayer2.util.Predicate<java.lang.String> contentTypePredicate,
com.google.android.exoplayer2.upstream.TransferListener<? super OkHttpDataSource> listener,
okhttp3.CacheControl cacheControl,
com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties) |
| Modifier and Type | Method and Description |
|---|---|
protected long |
bytesRead()
Returns the number of bytes that have been read since the most recent call to
open(DataSpec). |
protected long |
bytesRemaining()
Returns the number of bytes that are still to be read for the current
DataSpec. |
protected long |
bytesSkipped()
Returns the number of bytes that have been skipped since the most recent call to
open(DataSpec). |
void |
clearAllRequestProperties() |
void |
clearRequestProperty(java.lang.String name) |
void |
close() |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaders() |
android.net.Uri |
getUri() |
long |
open(com.google.android.exoplayer2.upstream.DataSpec dataSpec) |
int |
read(byte[] buffer,
int offset,
int readLength) |
void |
setRequestProperty(java.lang.String name,
java.lang.String value) |
public OkHttpDataSource(@NonNull
okhttp3.Call.Factory callFactory,
@Nullable
java.lang.String userAgent,
@Nullable
com.google.android.exoplayer2.util.Predicate<java.lang.String> contentTypePredicate)
callFactory - A Call.Factory (typically an OkHttpClient) for use
by the source.userAgent - An optional User-Agent string.contentTypePredicate - An optional Predicate. If a content type is rejected by the
predicate then a InvalidContentTypeException} is thrown from open(DataSpec).public OkHttpDataSource(@NonNull
okhttp3.Call.Factory callFactory,
@Nullable
java.lang.String userAgent,
@Nullable
com.google.android.exoplayer2.util.Predicate<java.lang.String> contentTypePredicate,
@Nullable
com.google.android.exoplayer2.upstream.TransferListener<? super OkHttpDataSource> listener)
callFactory - A Call.Factory (typically an OkHttpClient) for use
by the source.userAgent - An optional User-Agent string.contentTypePredicate - An optional Predicate. If a content type is rejected by the
predicate then a InvalidContentTypeException is thrown from
open(DataSpec).listener - An optional listener.public OkHttpDataSource(@NonNull
okhttp3.Call.Factory callFactory,
@Nullable
java.lang.String userAgent,
@Nullable
com.google.android.exoplayer2.util.Predicate<java.lang.String> contentTypePredicate,
@Nullable
com.google.android.exoplayer2.upstream.TransferListener<? super OkHttpDataSource> listener,
@Nullable
okhttp3.CacheControl cacheControl,
@Nullable
com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties)
callFactory - A Call.Factory (typically an OkHttpClient) for use
by the source.userAgent - An optional User-Agent string.contentTypePredicate - An optional Predicate. If a content type is rejected by the
predicate then a InvalidContentTypeException is thrown from
open(DataSpec).listener - An optional listener.cacheControl - An optional CacheControl for setting the Cache-Control header.defaultRequestProperties - The optional default RequestProperties to be sent to
the server as HTTP headers on every request.public android.net.Uri getUri()
getUri in interface com.google.android.exoplayer2.upstream.DataSourcepublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaders()
getResponseHeaders in interface com.google.android.exoplayer2.upstream.HttpDataSourcepublic void setRequestProperty(java.lang.String name,
java.lang.String value)
setRequestProperty in interface com.google.android.exoplayer2.upstream.HttpDataSourcepublic void clearRequestProperty(java.lang.String name)
clearRequestProperty in interface com.google.android.exoplayer2.upstream.HttpDataSourcepublic void clearAllRequestProperties()
clearAllRequestProperties in interface com.google.android.exoplayer2.upstream.HttpDataSourcepublic long open(com.google.android.exoplayer2.upstream.DataSpec dataSpec)
throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
open in interface com.google.android.exoplayer2.upstream.DataSourceopen in interface com.google.android.exoplayer2.upstream.HttpDataSourcecom.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceExceptionpublic int read(byte[] buffer,
int offset,
int readLength)
throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
read in interface com.google.android.exoplayer2.upstream.DataSourceread in interface com.google.android.exoplayer2.upstream.HttpDataSourcecom.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceExceptionpublic void close()
throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
close in interface com.google.android.exoplayer2.upstream.DataSourceclose in interface com.google.android.exoplayer2.upstream.HttpDataSourcecom.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceExceptionprotected final long bytesSkipped()
open(DataSpec).protected final long bytesRead()
open(DataSpec).protected final long bytesRemaining()
DataSpec.
If the total length of the data being read is known, then this length minus bytesRead()
is returned. If the total length is unknown, C.LENGTH_UNSET is returned.
C.LENGTH_UNSET.