Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,19 @@ package androidx.media3.datasource.okhttp {

}

package androidx.media3.datasource.ktor {

public class KtorDataSource implements androidx.media3.datasource.DataSource androidx.media3.datasource.HttpDataSource {
}

public static final class KtorDataSource.Factory implements androidx.media3.datasource.HttpDataSource.Factory {
ctor public KtorDataSource.Factory(io.ktor.client.HttpClient);
ctor public KtorDataSource.Factory(io.ktor.client.HttpClient, kotlinx.coroutines.CoroutineScope);
method public androidx.media3.datasource.ktor.KtorDataSource.Factory setUserAgent(@Nullable String);
}

}

package androidx.media3.exoplayer {

public final class ExoPlaybackException extends androidx.media3.common.PlaybackException {
Expand Down
1 change: 1 addition & 0 deletions constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ project.ext {
desugarJdkLibsVersion = '2.1.5'
lottieVersion = '6.6.0'
truthVersion = '1.4.0'
ktorVersion = '3.0.3'
okhttpVersion = '4.12.0'
testParameterInjectorVersion = '1.18'
modulePrefix = ':'
Expand Down
2 changes: 2 additions & 0 deletions core_settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ include modulePrefix + 'lib-datasource-rtmp'
project(modulePrefix + 'lib-datasource-rtmp').projectDir = new File(rootDir, 'libraries/datasource_rtmp')
include modulePrefix + 'lib-datasource-okhttp'
project(modulePrefix + 'lib-datasource-okhttp').projectDir = new File(rootDir, 'libraries/datasource_okhttp')
include modulePrefix + 'lib-datasource-ktor'
project(modulePrefix + 'lib-datasource-ktor').projectDir = new File(rootDir, 'libraries/datasource_ktor')

include modulePrefix + 'lib-decoder'
project(modulePrefix + 'lib-decoder').projectDir = new File(rootDir, 'libraries/decoder')
Expand Down
64 changes: 64 additions & 0 deletions libraries/datasource_ktor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Ktor DataSource module

This module provides an [HttpDataSource][] implementation that uses [Ktor][].

Ktor is a multiplatform HTTP client developed by JetBrains. It supports HTTP/2,
WebSocket, and Kotlin coroutines for asynchronous operations.

[HttpDataSource]: ../datasource/src/main/java/androidx/media3/datasource/HttpDataSource.java
[Ktor]: https://ktor.io/

## Getting the module

The easiest way to get the module is to add it as a gradle dependency:

```groovy
implementation 'androidx.media3:media3-datasource-ktor:1.X.X'
```

where `1.X.X` is the version, which must match the version of the other media
modules being used.

Alternatively, you can clone this GitHub project and depend on the module
locally. Instructions for doing this can be found in the [top level README][].

[top level README]: ../../README.md

## Using the module

Media components request data through `DataSource` instances. These instances
are obtained from instances of `DataSource.Factory`, which are instantiated and
injected from application code.

If your application only needs to play http(s) content, using the Ktor
extension is as simple as updating any `DataSource.Factory` instantiations in
your application code to use `KtorDataSource.Factory`. If your application
also needs to play non-http(s) content such as local files, use:
```
new DefaultDataSourceFactory(
...
/* baseDataSourceFactory= */ new KtorDataSource.Factory(...));
```

### Using with OkHttp engine

```kotlin
val dataSourceFactory = KtorDataSource.Factory(OkHttp.create())
```

### Using with a custom HttpClient

```kotlin
val httpClient = HttpClient(OkHttp) {
engine {
// Configure OkHttp engine
}
}
val dataSourceFactory = KtorDataSource.Factory(httpClient)
```

## Links

* [Javadoc][]

[Javadoc]: https://developer.android.com/reference/androidx/media3/datasource/ktor/package-summary
41 changes: 41 additions & 0 deletions libraries/datasource_ktor/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply from: "$gradle.ext.androidxMediaSettingsDir/common_library_config.gradle"

apply plugin: 'kotlin-android'

android {
namespace 'androidx.media3.datasource.ktor'

defaultConfig.minSdkVersion project.ext.minSdkVersion

publishing {
singleVariant('release') {
withSourcesJar()
}
}

kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
api project(modulePrefix + 'lib-common')
api project(modulePrefix + 'lib-datasource')
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
compileOnly 'com.google.errorprone:error_prone_annotations:' + errorProneVersion
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:' + kotlinxCoroutinesVersion
testImplementation project(modulePrefix + 'test-utils')
testImplementation 'com.squareup.okhttp3:mockwebserver:' + okhttpVersion
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
testImplementation 'io.ktor:ktor-client-okhttp:' + ktorVersion
api 'io.ktor:ktor-client-core:' + ktorVersion
}

ext {
releaseArtifactId = 'media3-datasource-ktor'
releaseName = 'Media3 Ktor DataSource module'

}
apply from: '../../publish.gradle'
11 changes: 11 additions & 0 deletions libraries/datasource_ktor/proguard-rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Proguard rules specific to the Ktor extension.

# Options for Ktor and Okio
-dontwarn io.ktor.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-dontwarn org.conscrypt.**

# Keep Ktor client classes
-keep class io.ktor.** { *; }
-keep class kotlinx.coroutines.** { *; }
4 changes: 4 additions & 0 deletions libraries/datasource_ktor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="androidx.media3.datasource.ktor">
<uses-sdk />
</manifest>
Loading