Class CronetDataSource.Factory
- java.lang.Object
-
- com.google.android.exoplayer2.ext.cronet.CronetDataSource.Factory
-
- All Implemented Interfaces:
DataSource.Factory
,HttpDataSource.Factory
- Enclosing class:
- CronetDataSource
public static final class CronetDataSource.Factory extends Object implements HttpDataSource.Factory
DataSource.Factory
forCronetDataSource
instances.
-
-
Constructor Summary
Constructors Constructor Description Factory(CronetEngineWrapper cronetEngineWrapper, Executor executor)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpDataSource
createDataSource()
Creates aDataSource
instance.HttpDataSource.RequestProperties
getDefaultRequestProperties()
Deprecated.UsesetDefaultRequestProperties(Map)
instead.CronetDataSource.Factory
setConnectionTimeoutMs(int connectTimeoutMs)
Sets the connect timeout, in milliseconds.CronetDataSource.Factory
setContentTypePredicate(Predicate<String> contentTypePredicate)
Sets a content typePredicate
.CronetDataSource.Factory
setDefaultRequestProperties(Map<String,String> defaultRequestProperties)
Sets the default request headers forHttpDataSource
instances created by the factory.CronetDataSource.Factory
setFallbackFactory(HttpDataSource.Factory fallbackFactory)
Sets the fallbackHttpDataSource.Factory
that is used as a fallback if theCronetEngineWrapper
fails to provide aCronetEngine
.CronetDataSource.Factory
setHandleSetCookieRequests(boolean handleSetCookieRequests)
Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.CronetDataSource.Factory
setReadTimeoutMs(int readTimeoutMs)
Sets the read timeout, in milliseconds.CronetDataSource.Factory
setResetTimeoutOnRedirects(boolean resetTimeoutOnRedirects)
Sets whether the connect timeout is reset when a redirect occurs.CronetDataSource.Factory
setTransferListener(TransferListener transferListener)
Sets theTransferListener
that will be used.CronetDataSource.Factory
setUserAgent(String userAgent)
Sets the user agent that will be used.
-
-
-
Constructor Detail
-
Factory
public Factory(CronetEngineWrapper cronetEngineWrapper, Executor executor)
Creates an instance.- Parameters:
cronetEngineWrapper
- ACronetEngineWrapper
.executor
- TheExecutor
that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from Cronet's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor.
-
-
Method Detail
-
getDefaultRequestProperties
@Deprecated public final HttpDataSource.RequestProperties getDefaultRequestProperties()
Deprecated.UsesetDefaultRequestProperties(Map)
instead.- Specified by:
getDefaultRequestProperties
in interfaceHttpDataSource.Factory
-
setDefaultRequestProperties
public final CronetDataSource.Factory setDefaultRequestProperties(Map<String,String> defaultRequestProperties)
Description copied from interface:HttpDataSource.Factory
Sets the default request headers forHttpDataSource
instances created by the factory.The new request properties will be used for future requests made by
HttpDataSources
created by the factory, including instances that have already been created. Modifying thedefaultRequestProperties
map after a call to this method will have no effect, and so it's necessary to call this method again each time the request properties need to be updated.- Specified by:
setDefaultRequestProperties
in interfaceHttpDataSource.Factory
- Parameters:
defaultRequestProperties
- The default request properties.- Returns:
- This factory.
-
setUserAgent
public CronetDataSource.Factory setUserAgent(@Nullable String userAgent)
Sets the user agent that will be used.The default is
null
, which causes the default user agent of the underlyingCronetEngine
to be used.- Parameters:
userAgent
- The user agent that will be used, ornull
to use the default user agent of the underlyingCronetEngine
.- Returns:
- This factory.
-
setConnectionTimeoutMs
public CronetDataSource.Factory setConnectionTimeoutMs(int connectTimeoutMs)
Sets the connect timeout, in milliseconds.The default is
CronetDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS
.- Parameters:
connectTimeoutMs
- The connect timeout, in milliseconds, that will be used.- Returns:
- This factory.
-
setResetTimeoutOnRedirects
public CronetDataSource.Factory setResetTimeoutOnRedirects(boolean resetTimeoutOnRedirects)
Sets whether the connect timeout is reset when a redirect occurs.The default is
false
.- Parameters:
resetTimeoutOnRedirects
- Whether the connect timeout is reset when a redirect occurs.- Returns:
- This factory.
-
setHandleSetCookieRequests
public CronetDataSource.Factory setHandleSetCookieRequests(boolean handleSetCookieRequests)
Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.The default is
false
.- Parameters:
handleSetCookieRequests
- Whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.- Returns:
- This factory.
-
setReadTimeoutMs
public CronetDataSource.Factory setReadTimeoutMs(int readTimeoutMs)
Sets the read timeout, in milliseconds.The default is
CronetDataSource.DEFAULT_READ_TIMEOUT_MILLIS
.- Parameters:
readTimeoutMs
- The connect timeout, in milliseconds, that will be used.- Returns:
- This factory.
-
setContentTypePredicate
public CronetDataSource.Factory setContentTypePredicate(@Nullable Predicate<String> contentTypePredicate)
Sets a content typePredicate
. If a content type is rejected by the predicate then aHttpDataSource.InvalidContentTypeException
is thrown fromDataSource.open(DataSpec)
.The default is
null
.- Parameters:
contentTypePredicate
- The content typePredicate
, ornull
to clear a predicate that was previously set.- Returns:
- This factory.
-
setTransferListener
public CronetDataSource.Factory setTransferListener(@Nullable TransferListener transferListener)
Sets theTransferListener
that will be used.The default is
null
.- Parameters:
transferListener
- The listener that will be used.- Returns:
- This factory.
-
setFallbackFactory
public CronetDataSource.Factory setFallbackFactory(@Nullable HttpDataSource.Factory fallbackFactory)
Sets the fallbackHttpDataSource.Factory
that is used as a fallback if theCronetEngineWrapper
fails to provide aCronetEngine
.By default a
DefaultHttpDataSource
is used as fallback factory.- Parameters:
fallbackFactory
- The fallback factory that will be used.- Returns:
- This factory.
-
createDataSource
public HttpDataSource createDataSource()
Description copied from interface:DataSource.Factory
Creates aDataSource
instance.- Specified by:
createDataSource
in interfaceDataSource.Factory
- Specified by:
createDataSource
in interfaceHttpDataSource.Factory
-
-