OkHttpDataSource.Factory


class OkHttpDataSource.Factory : HttpDataSource.Factory


DataSource.Factory for OkHttpDataSource instances.

Summary

Public constructors

Factory(callFactory: Call.Factory!)

Creates an instance.

Public functions

OkHttpDataSource!

Creates a DataSource instance.

OkHttpDataSource.Factory!

Sets the CacheControl that will be used.

OkHttpDataSource.Factory!

Sets a content type Predicate.

OkHttpDataSource.Factory!

Sets the default request headers for HttpDataSource instances created by the factory.

OkHttpDataSource.Factory!

Sets the TransferListener that will be used.

OkHttpDataSource.Factory!

Sets the user agent that will be used.

Inherited functions

From androidx.media3.datasource.DataSource.Factory
abstract DataSource!

Creates a DataSource instance.

Public constructors

Factory

Factory(callFactory: Call.Factory!)

Creates an instance.

Parameters
callFactory: Call.Factory!

A Call.Factory (typically an OkHttpClient) for use by the sources created by the factory.

Public functions

createDataSource

@UnstableApi
fun createDataSource(): OkHttpDataSource!

Creates a DataSource instance.

setCacheControl

@CanIgnoreReturnValue
@UnstableApi
fun setCacheControl(cacheControl: CacheControl?): OkHttpDataSource.Factory!

Sets the CacheControl that will be used.

The default is null.

Parameters
cacheControl: CacheControl?

The cache control that will be used.

Returns
OkHttpDataSource.Factory!

This factory.

setContentTypePredicate

@CanIgnoreReturnValue
@UnstableApi
fun setContentTypePredicate(contentTypePredicate: Predicate<String!>?): OkHttpDataSource.Factory!

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

The default is null.

Parameters
contentTypePredicate: Predicate<String!>?

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

Returns
OkHttpDataSource.Factory!

This factory.

setDefaultRequestProperties

@CanIgnoreReturnValue
@UnstableApi
fun setDefaultRequestProperties(
    defaultRequestProperties: (Mutable)Map<String!, String!>!
): OkHttpDataSource.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.

Parameters
defaultRequestProperties: (Mutable)Map<String!, String!>!

The default request properties.

Returns
OkHttpDataSource.Factory!

This factory.

setTransferListener

@CanIgnoreReturnValue
@UnstableApi
fun setTransferListener(transferListener: TransferListener?): OkHttpDataSource.Factory!

Sets the TransferListener that will be used.

The default is null.

See addTransferListener.

Parameters
transferListener: TransferListener?

The listener that will be used.

Returns
OkHttpDataSource.Factory!

This factory.

setUserAgent

@CanIgnoreReturnValue
@UnstableApi
fun setUserAgent(userAgent: String?): OkHttpDataSource.Factory!

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: String?

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

Returns
OkHttpDataSource.Factory!

This factory.