Class OkHttpDataSource.Factory
- java.lang.Object
-
- com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource.Factory
-
- All Implemented Interfaces:
DataSource.Factory
,HttpDataSource.Factory
- Enclosing class:
- OkHttpDataSource
public static final class OkHttpDataSource.Factory extends Object implements HttpDataSource.Factory
DataSource.Factory
forOkHttpDataSource
instances.
-
-
Constructor Summary
Constructors Constructor Description Factory(okhttp3.Call.Factory callFactory)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OkHttpDataSource
createDataSource()
Creates aDataSource
instance.OkHttpDataSource.Factory
setCacheControl(okhttp3.CacheControl cacheControl)
Sets theCacheControl
that will be used.OkHttpDataSource.Factory
setContentTypePredicate(Predicate<String> contentTypePredicate)
Sets a content typePredicate
.OkHttpDataSource.Factory
setDefaultRequestProperties(Map<String,String> defaultRequestProperties)
Sets the default request headers forHttpDataSource
instances created by the factory.OkHttpDataSource.Factory
setTransferListener(TransferListener transferListener)
Sets theTransferListener
that will be used.OkHttpDataSource.Factory
setUserAgent(String userAgent)
Sets the user agent that will be used.
-
-
-
Method Detail
-
setDefaultRequestProperties
@CanIgnoreReturnValue public final OkHttpDataSource.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
@CanIgnoreReturnValue public OkHttpDataSource.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 underlyingOkHttpClient
to be used.- Parameters:
userAgent
- The user agent that will be used, ornull
to use the default user agent of the underlyingOkHttpClient
.- Returns:
- This factory.
-
setCacheControl
@CanIgnoreReturnValue public OkHttpDataSource.Factory setCacheControl(@Nullable okhttp3.CacheControl cacheControl)
Sets theCacheControl
that will be used.The default is
null
.- Parameters:
cacheControl
- The cache control that will be used.- Returns:
- This factory.
-
setContentTypePredicate
@CanIgnoreReturnValue public OkHttpDataSource.Factory setContentTypePredicate(@Nullable Predicate<String> contentTypePredicate)
Sets a content typePredicate
. If a content type is rejected by the predicate then aHttpDataSource.InvalidContentTypeException
is thrown fromOkHttpDataSource.open(DataSpec)
.The default is
null
.- Parameters:
contentTypePredicate
- The content typePredicate
, ornull
to clear a predicate that was previously set.- Returns:
- This factory.
-
setTransferListener
@CanIgnoreReturnValue public OkHttpDataSource.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.
-
createDataSource
public OkHttpDataSource createDataSource()
Description copied from interface:DataSource.Factory
Creates aDataSource
instance.- Specified by:
createDataSource
in interfaceDataSource.Factory
- Specified by:
createDataSource
in interfaceHttpDataSource.Factory
-
-