public final class

CronetDataSource.Factory

extends java.lang.Object

implements HttpDataSource.Factory

 java.lang.Object

↳androidx.media3.datasource.cronet.CronetDataSource.Factory

Overview

for CronetDataSource instances.

Summary

Constructors
publicFactory(CronetEngine cronetEngine, java.util.concurrent.Executor executor)

Creates an instance.

Methods
public HttpDataSourcecreateDataSource()

public CronetDataSource.FactorysetConnectionTimeoutMs(int connectTimeoutMs)

Sets the connect timeout, in milliseconds.

public CronetDataSource.FactorysetContentTypePredicate(<any> contentTypePredicate)

Sets a content type .

public final CronetDataSource.FactorysetDefaultRequestProperties(java.util.Map<java.lang.String, java.lang.String> defaultRequestProperties)

public CronetDataSource.FactorysetFallbackFactory(HttpDataSource.Factory fallbackFactory)

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

public CronetDataSource.FactorysetHandleSetCookieRequests(boolean handleSetCookieRequests)

Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

public CronetDataSource.FactorysetKeepPostFor302Redirects(boolean keepPostFor302Redirects)

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

public CronetDataSource.FactorysetReadTimeoutMs(int readTimeoutMs)

Sets the read timeout, in milliseconds.

public CronetDataSource.FactorysetRequestPriority(int requestPriority)

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

public CronetDataSource.FactorysetResetTimeoutOnRedirects(boolean resetTimeoutOnRedirects)

Sets whether the connect timeout is reset when a redirect occurs.

public CronetDataSource.FactorysetTransferListener(TransferListener transferListener)

Sets the TransferListener that will be used.

public CronetDataSource.FactorysetUserAgent(java.lang.String userAgent)

Sets the user agent that will be used.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Factory(CronetEngine cronetEngine, java.util.concurrent.Executor executor)

Creates an instance.

Parameters:

cronetEngine: A 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 java.util.concurrent.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.

Methods

public final CronetDataSource.Factory setDefaultRequestProperties(java.util.Map<java.lang.String, java.lang.String> defaultRequestProperties)

public CronetDataSource.Factory setUserAgent(java.lang.String userAgent)

Sets the user agent that will be used.

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

Parameters:

userAgent: The user agent that will be used, or null to use the default user agent of the underlying .

Returns:

This factory.

public CronetDataSource.Factory setRequestPriority(int requestPriority)

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

The default is .

Parameters:

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

Returns:

This factory.

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.

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.

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.

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.

public CronetDataSource.Factory setContentTypePredicate(<any> contentTypePredicate)

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

The default is null.

Parameters:

contentTypePredicate: The content type , or null to clear a predicate that was previously set.

Returns:

This factory.

public 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.

public CronetDataSource.Factory setTransferListener(TransferListener 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.

public CronetDataSource.Factory setFallbackFactory(HttpDataSource.Factory fallbackFactory)

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

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

By default a DefaultHttpDataSource is used as fallback factory.

Parameters:

fallbackFactory: The fallback factory that will be used.

Returns:

This factory.

public HttpDataSource createDataSource()