From 1eced92b51349dd8b35550c2e81c5bb8d42d488b Mon Sep 17 00:00:00 2001
From: firelight <147925818+fire-light42@users.noreply.github.com>
Date: Thu, 23 Jan 2025 21:12:26 +0000
Subject: [PATCH] Added software decoding option
---
.../cloudstream3/ui/player/CS3IPlayer.kt | 26 +++++---
app/src/main/res/values/strings.xml | 3 +
app/src/main/res/xml/settings_player.xml | 60 +++++++++----------
3 files changed, 52 insertions(+), 37 deletions(-)
diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt
index ce5945af94..34d95606f5 100644
--- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt
+++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt
@@ -37,6 +37,7 @@ import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor
import androidx.media3.datasource.cache.SimpleCache
import androidx.media3.datasource.okhttp.OkHttpDataSource
import androidx.media3.exoplayer.DefaultLoadControl
+import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.Renderer.STATE_ENABLED
import androidx.media3.exoplayer.Renderer.STATE_STARTED
@@ -80,7 +81,6 @@ import com.lagradost.cloudstream3.utils.ExtractorLinkPlayList
import com.lagradost.cloudstream3.utils.ExtractorLinkType
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTwoLettersToLanguage
import io.github.anilbeesetti.nextlib.media3ext.ffdecoder.NextRenderersFactory
-import androidx.media3.exoplayer.DefaultRenderersFactory
import kotlinx.coroutines.delay
import java.io.File
import java.util.UUID
@@ -549,7 +549,7 @@ class CS3IPlayer : IPlayer {
exoPlayer?.apply {
playWhenReady = false
-
+
// This may look weird, however on some TV devices the audio does not stop playing
// so this may fix it?
try {
@@ -558,7 +558,7 @@ class CS3IPlayer : IPlayer {
// No documented exception, but just to be extra safe
logError(t)
}
-
+
stop()
release()
}
@@ -734,10 +734,22 @@ class CS3IPlayer : IPlayer {
ExoPlayer.Builder(context)
.setRenderersFactory { eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput ->
- NextRenderersFactory(context).apply {
- setEnableDecoderFallback(true)
- setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
- }.createRenderers(
+ val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
+ val softwareDecoding = settingsManager.getBoolean(
+ context.getString(R.string.software_decoding_key),
+ true
+ )
+
+ val factory = if (softwareDecoding) {
+ NextRenderersFactory(context).apply {
+ setEnableDecoderFallback(true)
+ setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
+ }
+ } else {
+ DefaultRenderersFactory(context)
+ }
+
+ factory.createRenderers(
eventHandler,
videoRendererEventListener,
audioRendererEventListener,
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 495a71fc8f..ecdffd5332 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -829,4 +829,7 @@
Edge Size
Enable torrent in Settings/Providers/Preferred media
Not accepted torrent
+ software_decoding_key
+ Software decoding
+ Software decoding enables the player to play video files not supported by your phone, but may cause laggy or unstable playback on high resolution
diff --git a/app/src/main/res/xml/settings_player.xml b/app/src/main/res/xml/settings_player.xml
index a2575e3152..8aac90b640 100644
--- a/app/src/main/res/xml/settings_player.xml
+++ b/app/src/main/res/xml/settings_player.xml
@@ -9,16 +9,15 @@
app:defaultValue="true"
app:key="@string/episode_sync_enabled_key" />
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+ android:title="@string/hide_player_control_names" />
-
+
-
+
+
-
+
@@ -153,8 +154,7 @@
app:showSeekBarValue="true" />
-
+
+ android:key="@string/pref_category_android_tv_key"
+ android:title="@string/pref_category_android_tv">