KtorDataSource.Factory


class KtorDataSource.Factory : HttpDataSource.Factory


androidx.media3.datasource.DataSource.Factory for KtorDataSource instances.

Summary

Public constructors

Factory(
    httpClient: HttpClient,
    userAgent: String?,
    contentTypePredicate: Predicate<String>?,
    transferListener: TransferListener?
)

Public functions

open KtorDataSource

Creates a DataSource instance.

open KtorDataSource.Factory
@CanIgnoreReturnValue
setDefaultRequestProperties(
    defaultRequestProperties: Map<StringString>
)

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

Public constructors

Factory

Factory(
    httpClient: HttpClient,
    userAgent: String? = null,
    contentTypePredicate: Predicate<String>? = null,
    transferListener: TransferListener? = null
)
Parameters
httpClient: HttpClient

A HttpClient for use by the sources created by the factory.

userAgent: String? = null

The user agent that will be used for requests. The default is null, which causes the default user agent of the underlying HttpClient to be used.

contentTypePredicate: Predicate<String>? = null

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

transferListener: TransferListener? = null

An optional transfer listener. See androidx.media3.datasource.DataSource.addTransferListener.

Public functions

createDataSource

open fun createDataSource(): KtorDataSource

Creates a DataSource instance.

setDefaultRequestProperties

@CanIgnoreReturnValue
open fun setDefaultRequestProperties(
    defaultRequestProperties: Map<StringString>
): KtorDataSource.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: Map<StringString>

The default request properties.

Returns
KtorDataSource.Factory

This factory.