# 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)

*** ** * ** ***


```
public final class KtorDataSource.Factory implements HttpDataSource.Factory
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/datasource/ktor/KtorDataSource` | `https://developer.android.com/reference/androidx/media3/datasource/ktor/KtorDataSource.Factory#createDataSource()()` Creates a `https://developer.android.com/reference/androidx/media3/datasource/DataSource` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/datasource/ktor/KtorDataSource.Factory` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/datasource/ktor/KtorDataSource.Factory#setDefaultRequestProperties(kotlin.collections.Map)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> defaultRequestProperties )` Sets the default request headers for `https://developer.android.com/reference/androidx/media3/datasource/HttpDataSource` instances created by the factory. |

## Public constructors

### Factory

```
public Factory(
    @NonNull HttpClient httpClient,
    String userAgent,
    Predicate<@NonNull String> contentTypePredicate,
    TransferListener transferListener
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html httpClient` | A `https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html` for use by the sources created by the factory. |
| `https://developer.android.com/reference/java/lang/String.html userAgent` | 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. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> contentTypePredicate` | 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/androidx/media3/datasource/HttpDataSource.InvalidContentTypeException` is thrown from `https://developer.android.com/reference/androidx/media3/datasource/ktor/KtorDataSource#open(androidx.media3.datasource.DataSpec)`. |
| `https://developer.android.com/reference/androidx/media3/datasource/TransferListener transferListener` | An optional transfer listener. See `https://developer.android.com/reference/androidx/media3/datasource/DataSource#addTransferListener(androidx.media3.datasource.TransferListener)`. |

## Public methods

### createDataSource

```
public @NonNull KtorDataSource createDataSource()
```

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

### setDefaultRequestProperties

```
@CanIgnoreReturnValue
public @NonNull KtorDataSource.Factory setDefaultRequestProperties(
    @NonNull Map<@NonNull String, @NonNull String> defaultRequestProperties
)
```

Sets the default request headers for `https://developer.android.com/reference/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> defaultRequestProperties` | The default request properties. |

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