# KtorDataSource.Factory

Artifact: [androidx.media3:media3-datasource-ktor](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/datasource/ktor/KtorDataSource.kt+class:androidx.media3.datasource.ktor.KtorDataSource.Factory)

*** ** * ** ***


```
class KtorDataSource.Factory : HttpDataSource.Factory
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory` for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource` instances.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource.Factory#Factory(io.ktor.client.HttpClient,kotlin.String,com.google.common.base.Predicate,androidx.media3.datasource.TransferListener)( httpClient: https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html, userAgent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, contentTypePredicate: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>?, transferListener: https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener? )` |

| ### Public functions |
|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource.Factory#createDataSource()()` Creates a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instance. |
| `open https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource.Factory` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource.Factory#setDefaultRequestProperties(kotlin.collections.Map)( defaultRequestProperties: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> )` Sets the default request headers for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource` instances created by the factory. |

## Public constructors

### Factory

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

| Parameters |
|---|---|
| `httpClient: https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html` | A `https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html` for use by the sources created by the factory. |
| `userAgent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | The user agent that will be used for requests. The default is `null`, which causes the default user agent of the underlying `https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html` to be used. |
| `contentTypePredicate: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>? = null` | An optional content type `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html`. If a content type is rejected by the predicate then a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.InvalidContentTypeException` is thrown from `https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource#open(androidx.media3.datasource.DataSpec)`. |
| `transferListener: https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener? = null` | An optional transfer listener. See `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#addTransferListener(androidx.media3.datasource.TransferListener)`. |

## Public functions

### createDataSource

```
open fun createDataSource(): KtorDataSource
```

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instance.

### setDefaultRequestProperties

```
@CanIgnoreReturnValue
open fun setDefaultRequestProperties(
    defaultRequestProperties: Map<String, String>
): KtorDataSource.Factory
```

Sets the default request headers for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource` instances created by the factory.

The new request properties will be used for future requests made by `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource` 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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | The default request properties. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/ktor/KtorDataSource.Factory` | This factory. |