Add ffmpeg audio decoding

This commit is contained in:
Lag 2023-03-17 15:46:11 +01:00
parent 7bfcf25df4
commit 8ebf5185a3
2 changed files with 28 additions and 18 deletions

View file

@ -159,6 +159,8 @@ dependencies {
implementation("com.google.android.exoplayer:extension-cast:2.18.2") implementation("com.google.android.exoplayer:extension-cast:2.18.2")
implementation("com.google.android.exoplayer:extension-mediasession:2.18.2") implementation("com.google.android.exoplayer:extension-mediasession:2.18.2")
implementation("com.google.android.exoplayer:extension-okhttp:2.18.2") implementation("com.google.android.exoplayer:extension-okhttp:2.18.2")
// Use the Jellyfin ffmpeg extension for easy ffmpeg audio decoding in exoplayer. Thank you Jellyfin <3
implementation("org.jellyfin.exoplayer:exoplayer-ffmpeg-extension:2.18.2+1")
//implementation("com.google.android.exoplayer:extension-leanback:2.14.0") //implementation("com.google.android.exoplayer:extension-leanback:2.14.0")

View file

@ -9,8 +9,11 @@ import android.widget.FrameLayout
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.google.android.exoplayer2.* import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.C.* import com.google.android.exoplayer2.C.*
import com.google.android.exoplayer2.DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON
import com.google.android.exoplayer2.DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider import com.google.android.exoplayer2.database.StandaloneDatabaseProvider
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector
import com.google.android.exoplayer2.source.* import com.google.android.exoplayer2.source.*
import com.google.android.exoplayer2.text.TextRenderer import com.google.android.exoplayer2.text.TextRenderer
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
@ -538,7 +541,8 @@ class CS3IPlayer : IPlayer {
} }
// Do no include empty referer, if the provider wants those they can use the header map. // Do no include empty referer, if the provider wants those they can use the header map.
val refererMap = if (link.referer.isBlank()) emptyMap() else mapOf("referer" to link.referer) val refererMap =
if (link.referer.isBlank()) emptyMap() else mapOf("referer" to link.referer)
val headers = mapOf( val headers = mapOf(
"accept" to "*/*", "accept" to "*/*",
"sec-ch-ua" to "\"Chromium\";v=\"91\", \" Not;A Brand\";v=\"99\"", "sec-ch-ua" to "\"Chromium\";v=\"91\", \" Not;A Brand\";v=\"99\"",
@ -669,23 +673,27 @@ class CS3IPlayer : IPlayer {
val exoPlayerBuilder = val exoPlayerBuilder =
ExoPlayer.Builder(context) ExoPlayer.Builder(context)
.setRenderersFactory { eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput -> .setRenderersFactory { eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput ->
DefaultRenderersFactory(context).createRenderers( DefaultRenderersFactory(context).apply {
eventHandler, setEnableDecoderFallback(true)
videoRendererEventListener, // Enable Ffmpeg extension
audioRendererEventListener, setExtensionRendererMode(EXTENSION_RENDERER_MODE_ON)
textRendererOutput, }.createRenderers(
metadataRendererOutput eventHandler,
).map { videoRendererEventListener,
if (it is TextRenderer) { audioRendererEventListener,
currentTextRenderer = CustomTextRenderer( textRendererOutput,
subtitleOffset, metadataRendererOutput
textRendererOutput, ).map {
eventHandler.looper, if (it is TextRenderer) {
CustomSubtitleDecoderFactory() currentTextRenderer = CustomTextRenderer(
) subtitleOffset,
currentTextRenderer!! textRendererOutput,
} else it eventHandler.looper,
}.toTypedArray() CustomSubtitleDecoderFactory()
)
currentTextRenderer!!
} else it
}.toTypedArray()
} }
.setTrackSelector( .setTrackSelector(
trackSelector ?: getTrackSelector( trackSelector ?: getTrackSelector(