Back to Exoplayer

CronetDataSource.Factory (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/ext/cronet/CronetDataSource.Factory.html

latest15.9 KB
Original Source

Package com.google.android.exoplayer2.ext.cronet

Class CronetDataSource.Factory

  • java.lang.Object

    • com.google.android.exoplayer2.ext.cronet.CronetDataSource.Factory
  • All Implemented Interfaces:DataSource.Factory, HttpDataSource.FactoryEnclosing class:CronetDataSource


public static final classCronetDataSource.Factoryextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[HttpDataSource.Factory](../../upstream/HttpDataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")

DataSource.Factory for CronetDataSource instances.

Constructor Summary

Constructors | Constructor | Description | | --- | --- | | Factory​(CronetEngineWrapper cronetEngineWrapper, Executor executor) | Deprecated. Use Factory(CronetEngine, Executor) with an instantiated CronetEngine, or DefaultHttpDataSource for cases where CronetEngineWrapper.getCronetEngine() would have returned null.

| | Factory​(org.chromium.net.CronetEngine cronetEngine, Executor executor) | Creates an instance. |

Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | HttpDataSource | createDataSource() | Creates a DataSource instance. | | CronetDataSource.Factory | setConnectionTimeoutMs​(int connectTimeoutMs) | Sets the connect timeout, in milliseconds. | | CronetDataSource.Factory | setContentTypePredicate​(Predicate<String> contentTypePredicate) | Sets a content type Predicate. | | CronetDataSource.Factory | setDefaultRequestProperties​(Map<String,​String> defaultRequestProperties) | Sets the default request headers for HttpDataSource instances created by the factory. | | CronetDataSource.Factory | setFallbackFactory​(HttpDataSource.Factory fallbackFactory) | Deprecated. Do not use CronetDataSource or its factory in cases where a suitable CronetEngine is not available.

| | 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 | setKeepPostFor302Redirects​(boolean keepPostFor302Redirects) | Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request. | | CronetDataSource.Factory | setReadTimeoutMs​(int readTimeoutMs) | Sets the read timeout, in milliseconds. | | CronetDataSource.Factory | setRequestPriority​(int requestPriority) | Sets the priority of requests made by CronetDataSource instances created by this factory. | | CronetDataSource.Factory | setResetTimeoutOnRedirects​(boolean resetTimeoutOnRedirects) | Sets whether the connect timeout is reset when a redirect occurs. | | CronetDataSource.Factory | setTransferListener​(TransferListener transferListener) | Sets the TransferListener that will be used. | | CronetDataSource.Factory | setUserAgent​(String userAgent) | Sets the user agent that will be used. |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

- 

Factory

public Factory​(org.chromium.net.CronetEngine cronetEngine,[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html "class or interface in java.util.concurrent")executor)

Creates an instance. Parameters:cronetEngine - A CronetEngine to make the requests. This should not be a fallback instance obtained from JavaCronetProvider. It's more efficient to use DefaultHttpDataSource instead in this case.executor - The Executor 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.

- 

Factory

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public Factory​([CronetEngineWrapper](CronetEngineWrapper.html "class in com.google.android.exoplayer2.ext.cronet")cronetEngineWrapper,[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html "class or interface in java.util.concurrent")executor)

Deprecated. Use Factory(CronetEngine, Executor) with an instantiated CronetEngine, or DefaultHttpDataSource for cases where CronetEngineWrapper.getCronetEngine() would have returned null.

Creates an instance. Parameters:cronetEngineWrapper - A CronetEngineWrapper.executor - The Executor 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

- 

setDefaultRequestProperties

@CanIgnoreReturnValue
public final[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")setDefaultRequestProperties​([Map](https://developer.android.com/reference/java/util/Map.html "class or interface in java.util")<[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang"),​[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang")> defaultRequestProperties)

Description copied from interface: HttpDataSource.Factory

Sets the default request headers for HttpDataSource 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 the defaultRequestProperties 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 interface HttpDataSource.FactoryParameters:defaultRequestProperties - The default request properties.Returns:This factory.

- 

setUserAgent

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")setUserAgent​(@Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")userAgent)

Sets the user agent that will be used.

The default is null, which causes the default user agent of the underlying CronetEngine to be used.

Parameters:userAgent - The user agent that will be used, or null to use the default user agent of the underlying CronetEngine.Returns:This factory.

- 

setRequestPriority

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")setRequestPriority​(int requestPriority)

Sets the priority of requests made by CronetDataSource instances created by this factory.

The default is UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM.

Parameters:requestPriority - The request priority, which should be one of Cronet's UrlRequest.Builder#REQUEST_PRIORITY_* constants.Returns:This factory.

- 

setConnectionTimeoutMs

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")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

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")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

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")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

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")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

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")setContentTypePredicate​(@Nullable[Predicate](https://guava.dev/releases/31.1-android/api/docs/com/google/common/base/Predicate.html?is-external=true "class or interface in com.google.common.base")<[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")> contentTypePredicate)

Sets a content type Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from DataSource.open(DataSpec).

The default is null.

Parameters:contentTypePredicate - The content type Predicate, or null to clear a predicate that was previously set.Returns:This factory.

- 

setKeepPostFor302Redirects

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")setKeepPostFor302Redirects​(boolean keepPostFor302Redirects)

Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.

- 

setTransferListener

@CanIgnoreReturnValue
public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")setTransferListener​(@Nullable[TransferListener](../../upstream/TransferListener.html "interface in com.google.android.exoplayer2.upstream")transferListener)

Sets the TransferListener that will be used.

The default is null.

See DataSource.addTransferListener(TransferListener).

Parameters:transferListener - The listener that will be used.Returns:This factory.

- 

setFallbackFactory

@CanIgnoreReturnValue[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public[CronetDataSource.Factory](CronetDataSource.Factory.html "class in com.google.android.exoplayer2.ext.cronet")setFallbackFactory​(@Nullable[HttpDataSource.Factory](../../upstream/HttpDataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")fallbackFactory)

Deprecated. Do not use CronetDataSource or its factory in cases where a suitable CronetEngine is not available. Use the fallback factory directly in such cases.

Sets the fallback HttpDataSource.Factory that is used as a fallback if the CronetEngineWrapper fails to provide a CronetEngine.

By default a DefaultHttpDataSource is used as fallback factory.

Parameters:fallbackFactory - The fallback factory that will be used.Returns:This factory.

- 

createDataSource

public[HttpDataSource](../../upstream/HttpDataSource.html "interface in com.google.android.exoplayer2.upstream")createDataSource()

Description copied from interface: DataSource.Factory

Creates a DataSource instance. Specified by:createDataSource in interface DataSource.FactorySpecified by:createDataSource in interface HttpDataSource.Factory