Skip to content

Commit

Permalink
software decoding auto
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst authored Feb 1, 2025
1 parent e5ac4a0 commit 6ff6463
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.debugAssert
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
import com.lagradost.cloudstream3.utils.AppContextUtils.isUsingMobileData
import com.lagradost.cloudstream3.utils.AppContextUtils.setDefaultFocus
Expand Down Expand Up @@ -739,12 +741,17 @@ class CS3IPlayer : IPlayer {
val exoPlayerBuilder =
ExoPlayer.Builder(context)
.setRenderersFactory { eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput ->

val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
val softwareDecoding = settingsManager.getBoolean(
context.getString(R.string.software_decoding_key),
true
)
val current = settingsManager.getInt(context.getString(R.string.software_decoding_key), -1)
val softwareDecoding = when(current) {
0 -> true // yes
1 -> false // no
// -1 = automatic
else -> {
// we do not want tv to have software decoding, because of crashes
!isLayout(TV)
}
}

val factory = if (softwareDecoding) {
NextRenderersFactory(context).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ object Torrent {

/** Removes all torrents from the server, and returns if it is successful */
suspend fun clearAll(): Boolean {
if(TORRENT_SERVER_URL.isEmpty()) {
return true
}
return try {
val items = list()
var allSuccess = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ class SettingsPlayer : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}

getPref(R.string.software_decoding_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.software_decoding_switch)
val prefValues = resources.getIntArray(R.array.software_decoding_switch_values)
val current = settingsManager.getInt(getString(R.string.software_decoding_key), -1)

activity?.showBottomDialog(
prefNames.toList(),
prefValues.indexOf(current),
getString(R.string.software_decoding),
true,
{}) {
settingsManager.edit()
.putInt(getString(R.string.software_decoding_key), prefValues[it])
.apply()
}
return@setOnPreferenceClickListener true
}

getPref(R.string.prefer_limit_title_rez_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.limit_title_rez_pref_names)
val prefValues = resources.getIntArray(R.array.limit_title_rez_pref_values)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@
<item>2</item>
</array>

<array name="software_decoding_switch">
<item>@string/automatic</item>
<item>@string/yes</item>
<item>@string/no</item>
</array>

<array name="software_decoding_switch_values">
<item>-1</item>
<item>0</item>
<item>1</item>
</array>

<array name="confirm_exit">
<item>@string/automatic</item>
<item>@string/show</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@
<string name="subs_edge_size">Edge Size</string>
<string name="torrent_preferred_media">Enable torrent in Settings/Providers/Preferred media</string>
<string name="torrent_not_accepted">Not accepted torrent</string>
<string name="software_decoding_key" translatable="false">software_decoding_key</string>
<string name="software_decoding_key" translatable="false">software_decoding_key2</string>
<string name="software_decoding">Software decoding</string>
<string name="software_decoding_desc">Software decoding enables the player to play video files not supported by your phone, but may cause laggy or unstable playback on high resolution</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/xml/settings_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
android:title="@string/preview_seekbar"
app:defaultValue="true"
app:key="@string/preview_seekbar_key" />
<SwitchPreference
<Preference
android:icon="@drawable/ic_baseline_extension_24"
android:summary="@string/software_decoding_desc"
android:title="@string/software_decoding"
Expand Down

0 comments on commit 6ff6463

Please sign in to comment.