diff --git a/data/build.gradle.kts b/data/build.gradle.kts index 4794c835..cc4885a7 100644 --- a/data/build.gradle.kts +++ b/data/build.gradle.kts @@ -33,6 +33,7 @@ dependencies { .startParameter .taskNames .find { it.contains("richCodec", ignoreCase = true) } != null + implementation(project(":data:codec")) if (richCodec) { implementation(project(":data:codec:rich")) } else { diff --git a/data/codec/build.gradle.kts b/data/codec/build.gradle.kts new file mode 100644 index 00000000..93f93cab --- /dev/null +++ b/data/codec/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + alias(libs.plugins.com.android.library) + alias(libs.plugins.org.jetbrains.kotlin.android) + alias(libs.plugins.com.google.devtools.ksp) +} + +android { + namespace = "com.m3u.data.codec" + kotlinOptions { + jvmTarget = "17" + } +} + +dependencies { + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + + implementation(libs.androidx.media3.exoplayer) + + implementation(libs.auto.service.annotations) + + ksp(libs.auto.service.ksp) +} \ No newline at end of file diff --git a/data/codec/consumer-rules.pro b/data/codec/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/data/codec/lite/build.gradle.kts b/data/codec/lite/build.gradle.kts index c79e4015..9ba6e5ce 100644 --- a/data/codec/lite/build.gradle.kts +++ b/data/codec/lite/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) + alias(libs.plugins.com.google.devtools.ksp) } android { @@ -11,8 +12,14 @@ android { } dependencies { + implementation(project(":data:codec")) + implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) implementation(libs.androidx.media3.exoplayer) + + implementation(libs.auto.service.annotations) + + ksp(libs.auto.service.ksp) } \ No newline at end of file diff --git a/data/codec/lite/src/main/java/com/m3u/data/codec/Codecs.kt b/data/codec/lite/src/main/java/com/m3u/data/codec/LiteCodecs.kt similarity index 61% rename from data/codec/lite/src/main/java/com/m3u/data/codec/Codecs.kt rename to data/codec/lite/src/main/java/com/m3u/data/codec/LiteCodecs.kt index 738e4319..af8861a2 100644 --- a/data/codec/lite/src/main/java/com/m3u/data/codec/Codecs.kt +++ b/data/codec/lite/src/main/java/com/m3u/data/codec/LiteCodecs.kt @@ -3,9 +3,11 @@ package com.m3u.data.codec import android.content.Context import androidx.media3.exoplayer.DefaultRenderersFactory import androidx.media3.exoplayer.RenderersFactory +import com.google.auto.service.AutoService -object Codecs { - fun createRenderersFactory(context: Context): RenderersFactory { +@AutoService(Codecs::class) +class LiteCodecs: Codecs { + override fun createRenderersFactory(context: Context): RenderersFactory { return DefaultRenderersFactory(context).apply { setEnableDecoderFallback(true) } diff --git a/data/codec/proguard-rules.pro b/data/codec/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/data/codec/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/data/codec/rich/build.gradle.kts b/data/codec/rich/build.gradle.kts index 4974f85b..d8e027a4 100644 --- a/data/codec/rich/build.gradle.kts +++ b/data/codec/rich/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) + alias(libs.plugins.com.google.devtools.ksp) } android { @@ -11,9 +12,15 @@ android { } dependencies { + implementation(project(":data:codec")) + implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) implementation(libs.androidx.media3.exoplayer) implementation(libs.nextlib.media3.ext) + + implementation(libs.auto.service.annotations) + + ksp(libs.auto.service.ksp) } \ No newline at end of file diff --git a/data/codec/rich/src/main/java/com/m3u/data/codec/Codecs.kt b/data/codec/rich/src/main/java/com/m3u/data/codec/RichCodec.kt similarity index 71% rename from data/codec/rich/src/main/java/com/m3u/data/codec/Codecs.kt rename to data/codec/rich/src/main/java/com/m3u/data/codec/RichCodec.kt index 5fc8413f..a7922e27 100644 --- a/data/codec/rich/src/main/java/com/m3u/data/codec/Codecs.kt +++ b/data/codec/rich/src/main/java/com/m3u/data/codec/RichCodec.kt @@ -3,10 +3,12 @@ package com.m3u.data.codec import android.content.Context import androidx.media3.exoplayer.DefaultRenderersFactory import androidx.media3.exoplayer.RenderersFactory +import com.google.auto.service.AutoService import io.github.anilbeesetti.nextlib.media3ext.ffdecoder.NextRenderersFactory -object Codecs { - fun createRenderersFactory(context: Context): RenderersFactory { +@AutoService(Codecs::class) +class RichCodec: Codecs { + override fun createRenderersFactory(context: Context): RenderersFactory { return NextRenderersFactory(context).apply { setEnableDecoderFallback(true) setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON) diff --git a/data/codec/src/main/java/com/m3u/data/codec/Codecs.kt b/data/codec/src/main/java/com/m3u/data/codec/Codecs.kt new file mode 100644 index 00000000..d05d2a2c --- /dev/null +++ b/data/codec/src/main/java/com/m3u/data/codec/Codecs.kt @@ -0,0 +1,15 @@ +package com.m3u.data.codec + +import android.content.Context +import androidx.media3.exoplayer.RenderersFactory +import java.util.ServiceLoader + +interface Codecs { + fun createRenderersFactory(context: Context): RenderersFactory + + companion object { + fun load(): Codecs { + return ServiceLoader.load(Codecs::class.java).first() + } + } +} \ No newline at end of file diff --git a/data/src/main/java/com/m3u/data/service/internal/PlayerManagerImpl.kt b/data/src/main/java/com/m3u/data/service/internal/PlayerManagerImpl.kt index 85dd3b20..d1f37776 100644 --- a/data/src/main/java/com/m3u/data/service/internal/PlayerManagerImpl.kt +++ b/data/src/main/java/com/m3u/data/service/internal/PlayerManagerImpl.kt @@ -369,7 +369,7 @@ class PlayerManagerImpl @Inject constructor( } private val renderersFactory: RenderersFactory by lazy { - Codecs.createRenderersFactory(context) + Codecs.load().createRenderersFactory(context) } private fun createTrackSelector(tunneling: Boolean): TrackSelector { diff --git a/settings.gradle.kts b/settings.gradle.kts index c11d0e6c..c9aaa3fe 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,7 +18,7 @@ rootProject.name = "M3U" include(":app:smartphone", ":app:tv") include(":core") include(":data") -include(":data:codec:lite", ":data:codec:rich") +include(":data:codec", ":data:codec:lite", ":data:codec:rich") include( ":business:foryou", ":business:favorite",