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.FactoryforOkHttpDataSourceinstances.
-
-
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 OkHttpDataSourcecreateDataSource()Creates aDataSourceinstance.OkHttpDataSource.FactorysetCacheControl(okhttp3.CacheControl cacheControl)Sets theCacheControlthat will be used.OkHttpDataSource.FactorysetContentTypePredicate(Predicate<String> contentTypePredicate)Sets a content typePredicate.OkHttpDataSource.FactorysetDefaultRequestProperties(Map<String,String> defaultRequestProperties)Sets the default request headers forHttpDataSourceinstances created by the factory.OkHttpDataSource.FactorysetTransferListener(TransferListener transferListener)Sets theTransferListenerthat will be used.OkHttpDataSource.FactorysetUserAgent(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.FactorySets the default request headers forHttpDataSourceinstances created by the factory.The new request properties will be used for future requests made by
HttpDataSourcescreated by the factory, including instances that have already been created. Modifying thedefaultRequestPropertiesmap 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:
setDefaultRequestPropertiesin 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 underlyingOkHttpClientto be used.- Parameters:
userAgent- The user agent that will be used, ornullto use the default user agent of the underlyingOkHttpClient.- Returns:
- This factory.
-
setCacheControl
@CanIgnoreReturnValue public OkHttpDataSource.Factory setCacheControl(@Nullable okhttp3.CacheControl cacheControl)
Sets theCacheControlthat 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.InvalidContentTypeExceptionis thrown fromOkHttpDataSource.open(DataSpec).The default is
null.- Parameters:
contentTypePredicate- The content typePredicate, ornullto clear a predicate that was previously set.- Returns:
- This factory.
-
setTransferListener
@CanIgnoreReturnValue public OkHttpDataSource.Factory setTransferListener(@Nullable TransferListener transferListener)
Sets theTransferListenerthat 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.FactoryCreates aDataSourceinstance.- Specified by:
createDataSourcein interfaceDataSource.Factory- Specified by:
createDataSourcein interfaceHttpDataSource.Factory
-
-