Class OkHttpDataSource
- java.lang.Object
-
- com.vng.android.exoplayer2.upstream.BaseDataSource
-
- com.vng.android.exoplayer2.ext.okhttp.OkHttpDataSource
-
- All Implemented Interfaces:
com.vng.android.exoplayer2.upstream.DataSource,com.vng.android.exoplayer2.upstream.HttpDataSource
public class OkHttpDataSource extends com.vng.android.exoplayer2.upstream.BaseDataSource implements com.vng.android.exoplayer2.upstream.HttpDataSourceAnHttpDataSourcethat delegates to Square'sCall.Factory.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vng.android.exoplayer2.upstream.DataSource
com.vng.android.exoplayer2.upstream.DataSource.Factory
-
Nested classes/interfaces inherited from interface com.vng.android.exoplayer2.upstream.HttpDataSource
com.vng.android.exoplayer2.upstream.HttpDataSource.BaseFactory, com.vng.android.exoplayer2.upstream.HttpDataSource.Factory, com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException, com.vng.android.exoplayer2.upstream.HttpDataSource.InvalidContentTypeException, com.vng.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException, com.vng.android.exoplayer2.upstream.HttpDataSource.RequestProperties
-
-
Constructor Summary
Constructors Constructor Description OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate)OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate, okhttp3.CacheControl cacheControl, com.vng.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longbytesRead()Returns the number of bytes that have been read since the most recent call toopen(DataSpec).protected longbytesRemaining()Returns the number of bytes that are still to be read for the currentDataSpec.protected longbytesSkipped()Returns the number of bytes that have been skipped since the most recent call toopen(DataSpec).voidclearAllRequestProperties()voidclearRequestProperty(String name)voidclose()Map<String,List<String>>getResponseHeaders()UrigetUri()longopen(com.vng.android.exoplayer2.upstream.DataSpec dataSpec)intread(byte[] buffer, int offset, int readLength)voidsetRequestProperty(String name, String value)-
Methods inherited from class com.vng.android.exoplayer2.upstream.BaseDataSource
addTransferListener, bytesTransferred, transferEnded, transferInitializing, transferStarted
-
-
-
-
Constructor Detail
-
OkHttpDataSource
public OkHttpDataSource(okhttp3.Call.Factory callFactory, @Nullable String userAgent, @Nullable com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate)- Parameters:
callFactory- ACall.Factory(typically anOkHttpClient) for use by the source.userAgent- An optional User-Agent string.contentTypePredicate- An optionalPredicate. If a content type is rejected by the predicate then aHttpDataSource.InvalidContentTypeExceptionis thrown fromopen(DataSpec).
-
OkHttpDataSource
public OkHttpDataSource(okhttp3.Call.Factory callFactory, @Nullable String userAgent, @Nullable com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate, @Nullable okhttp3.CacheControl cacheControl, @Nullable com.vng.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties)- Parameters:
callFactory- ACall.Factory(typically anOkHttpClient) for use by the source.userAgent- An optional User-Agent string.contentTypePredicate- An optionalPredicate. If a content type is rejected by the predicate then aHttpDataSource.InvalidContentTypeExceptionis thrown fromopen(DataSpec).cacheControl- An optionalCacheControlfor setting the Cache-Control header.defaultRequestProperties- The optional defaultHttpDataSource.RequestPropertiesto be sent to the server as HTTP headers on every request.
-
-
Method Detail
-
getUri
@Nullable public Uri getUri()
- Specified by:
getUriin interfacecom.vng.android.exoplayer2.upstream.DataSource
-
getResponseHeaders
public Map<String,List<String>> getResponseHeaders()
- Specified by:
getResponseHeadersin interfacecom.vng.android.exoplayer2.upstream.DataSource- Specified by:
getResponseHeadersin interfacecom.vng.android.exoplayer2.upstream.HttpDataSource
-
setRequestProperty
public void setRequestProperty(String name, String value)
- Specified by:
setRequestPropertyin interfacecom.vng.android.exoplayer2.upstream.HttpDataSource
-
clearRequestProperty
public void clearRequestProperty(String name)
- Specified by:
clearRequestPropertyin interfacecom.vng.android.exoplayer2.upstream.HttpDataSource
-
clearAllRequestProperties
public void clearAllRequestProperties()
- Specified by:
clearAllRequestPropertiesin interfacecom.vng.android.exoplayer2.upstream.HttpDataSource
-
open
public long open(com.vng.android.exoplayer2.upstream.DataSpec dataSpec) throws com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException- Specified by:
openin interfacecom.vng.android.exoplayer2.upstream.DataSource- Specified by:
openin interfacecom.vng.android.exoplayer2.upstream.HttpDataSource- Throws:
com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
-
read
public int read(byte[] buffer, int offset, int readLength) throws com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException- Specified by:
readin interfacecom.vng.android.exoplayer2.upstream.DataSource- Specified by:
readin interfacecom.vng.android.exoplayer2.upstream.HttpDataSource- Throws:
com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
-
close
public void close() throws com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException- Specified by:
closein interfacecom.vng.android.exoplayer2.upstream.DataSource- Specified by:
closein interfacecom.vng.android.exoplayer2.upstream.HttpDataSource- Throws:
com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
-
bytesSkipped
protected final long bytesSkipped()
Returns the number of bytes that have been skipped since the most recent call toopen(DataSpec).- Returns:
- The number of bytes skipped.
-
bytesRead
protected final long bytesRead()
Returns the number of bytes that have been read since the most recent call toopen(DataSpec).- Returns:
- The number of bytes read.
-
bytesRemaining
protected final long bytesRemaining()
Returns the number of bytes that are still to be read for the currentDataSpec.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_UNSETis returned.- Returns:
- The remaining length, or
C.LENGTH_UNSET.
-
-