Package com.castlabs.sdk.okhttp
Class OkHttpDataSource
java.lang.Object
com.castlabs.sdk.okhttp.OkHttpDataSource
- All Implemented Interfaces:
com.google.android.exoplayer2.upstream.DataSource
,com.google.android.exoplayer2.upstream.HttpDataSource
,okhttp3.Interceptor
public class OkHttpDataSource
extends Object
implements com.google.android.exoplayer2.upstream.HttpDataSource, okhttp3.Interceptor
An
HttpDataSource
that delegates to Square's Call.Factory
.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.upstream.HttpDataSource
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
Nested classes/interfaces inherited from interface okhttp3.Interceptor
okhttp3.Interceptor.Chain
-
Field Summary
Fields inherited from interface com.google.android.exoplayer2.upstream.HttpDataSource
REJECT_PAYWALL_TYPES
-
Constructor Summary
ConstructorDescriptionOkHttpDataSource
(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener) OkHttpDataSource
(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener) OkHttpDataSource
(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, okhttp3.CacheControl cacheControl, com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTransferListener
(com.google.android.exoplayer2.upstream.TransferListener listener) void
void
clearRequestProperty
(String name) void
close()
int
getUri()
okhttp3.Response
intercept
(okhttp3.Interceptor.Chain chain) long
open
(com.google.android.exoplayer2.upstream.DataSpec dataSpec) int
read
(byte[] buffer, int offset, int readLength) void
setRedirectListener
(com.google.android.exoplayer2.upstream.HttpRedirectListener listener) void
setRequestProperty
(String name, String value)
-
Constructor Details
-
OkHttpDataSource
public OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener) - Parameters:
callFactory
- ACall.Factory
(typically anOkHttpClient
) for use by the source.userAgent
- The User-Agent string that should be used.contentTypePredicate
- An optionalPredicate
. If a content type is rejected by the predicate then a InvalidContentTypeException} is thrown fromopen(DataSpec)
.clientCreatedListener
- A listener to inform about new OkHttpClients
-
OkHttpDataSource
public OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener) - Parameters:
callFactory
- ACall.Factory
(typically anOkHttpClient
) for use by the source.userAgent
- The User-Agent string that should be used.contentTypePredicate
- An optionalPredicate
. If a content type is rejected by the predicate then aHttpDataSource.InvalidContentTypeException
is thrown fromopen(DataSpec)
.listener
- An optional listener.networkConfiguration
- The network configurationclientCreatedListener
- A listener to inform about new OkHttpClients
-
OkHttpDataSource
public OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, com.google.android.exoplayer2.util.Predicate<String> contentTypePredicate, com.google.android.exoplayer2.upstream.TransferListener listener, okhttp3.CacheControl cacheControl, com.google.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties, NetworkConfiguration networkConfiguration, com.castlabs.sdk.okhttp.OkHttpClientCreatedListener clientCreatedListener) - Parameters:
callFactory
- ACall.Factory
(typically anOkHttpClient
) for use by the source.userAgent
- The User-Agent string that should be used.contentTypePredicate
- An optionalPredicate
. If a content type is rejected by the predicate then aHttpDataSource.InvalidContentTypeException
is thrown fromopen(DataSpec)
.listener
- An optional listener.cacheControl
- An optionalCacheControl
for setting the Cache-Control header.defaultRequestProperties
- The optional defaultHttpDataSource.RequestProperties
to be sent to the server as HTTP headers on every request.networkConfiguration
- The network configurationclientCreatedListener
- A listener to inform about new OkHttpClients
-
-
Method Details
-
getUri
- Specified by:
getUri
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
addTransferListener
public void addTransferListener(com.google.android.exoplayer2.upstream.TransferListener listener) - Specified by:
addTransferListener
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
getResponseHeaders
- Specified by:
getResponseHeaders
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Specified by:
getResponseHeaders
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
-
setRedirectListener
public void setRedirectListener(com.google.android.exoplayer2.upstream.HttpRedirectListener listener) - Specified by:
setRedirectListener
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
-
setRequestProperty
- Specified by:
setRequestProperty
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
-
clearRequestProperty
- Specified by:
clearRequestProperty
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
-
clearAllRequestProperties
public void clearAllRequestProperties()- Specified by:
clearAllRequestProperties
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
-
getResponseCode
public int getResponseCode()- Specified by:
getResponseCode
in interfacecom.google.android.exoplayer2.upstream.DataSource
-
open
public long open(com.google.android.exoplayer2.upstream.DataSpec dataSpec) throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException - Specified by:
open
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Specified by:
open
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
- Throws:
com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
-
read
public int read(byte[] buffer, int offset, int readLength) throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException - Specified by:
read
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Specified by:
read
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
- Throws:
com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
-
close
public void close() throws com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException- Specified by:
close
in interfacecom.google.android.exoplayer2.upstream.DataSource
- Specified by:
close
in interfacecom.google.android.exoplayer2.upstream.HttpDataSource
- Throws:
com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
-
intercept
- Specified by:
intercept
in interfaceokhttp3.Interceptor
- Throws:
IOException
-