Skip to content

Commit

Permalink
Added software decoding option
Browse files Browse the repository at this point in the history
  • Loading branch information
fire-light42 authored Jan 23, 2025
1 parent 94f012f commit 1eced92
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -558,7 +558,7 @@ class CS3IPlayer : IPlayer {
// No documented exception, but just to be extra safe
logError(t)
}

stop()
release()
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -829,4 +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">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>
60 changes: 30 additions & 30 deletions app/src/main/res/xml/settings_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@
app:defaultValue="true"
app:key="@string/episode_sync_enabled_key" />

<PreferenceCategory
android:title="@string/pref_category_defaults">
<!-- <Preference-->
<!-- android:icon="@drawable/ic_baseline_hd_24"-->
<!-- android:key="@string/quality_pref_key"-->
<!-- android:title="@string/watch_quality_pref" />-->
<!-- <Preference-->
<!-- android:icon="@drawable/ic_baseline_hd_24"-->
<!-- android:key="@string/quality_pref_mobile_data_key"-->
<!-- android:title="@string/watch_quality_pref_data" />-->
<PreferenceCategory android:title="@string/pref_category_defaults">
<!-- <Preference-->
<!-- android:icon="@drawable/ic_baseline_hd_24"-->
<!-- android:key="@string/quality_pref_key"-->
<!-- android:title="@string/watch_quality_pref" />-->
<!-- <Preference-->
<!-- android:icon="@drawable/ic_baseline_hd_24"-->
<!-- android:key="@string/quality_pref_mobile_data_key"-->
<!-- android:title="@string/watch_quality_pref_data" />-->

<Preference
android:icon="@drawable/netflix_play"
android:key="@string/player_default_key"
android:title="@string/player_pref" />
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_category_player_layout">
<PreferenceCategory android:title="@string/pref_category_player_layout">
<Preference
android:icon="@drawable/ic_baseline_text_format_24"
android:key="@string/prefer_limit_title_key"
Expand All @@ -38,15 +36,13 @@
android:key="@string/prefer_limit_title_rez_key"
android:title="@string/limit_title_rez" />
<SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_baseline_text_format_24"
android:key="@string/hide_player_control_names_key"
android:title="@string/hide_player_control_names"
android:defaultValue="false"
/>
android:title="@string/hide_player_control_names" />
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_category_subtitles">
<PreferenceCategory android:title="@string/pref_category_subtitles">
<Preference
android:icon="@drawable/ic_outline_subtitles_24"
android:key="@string/subtitle_settings_key"
Expand All @@ -60,8 +56,7 @@
</PreferenceCategory>


<PreferenceCategory
android:title="@string/pref_category_player_features">
<PreferenceCategory android:title="@string/pref_category_player_features">
<SwitchPreference
android:icon="@drawable/ic_baseline_picture_in_picture_alt_24"
android:summary="@string/picture_in_picture_des"
Expand All @@ -88,30 +83,36 @@
app:key="@string/autoplay_next_key" />
<SwitchPreference
android:icon="@drawable/ic_baseline_skip_next_24"
android:summary="@string/enable_skip_op_from_database_des"
android:title="@string/video_skip_op"
app:defaultValue="true"
android:summary="@string/enable_skip_op_from_database_des"
app:key="@string/enable_skip_op_from_database" />
<SwitchPreference
android:icon="@drawable/screen_rotation"
android:summary="@string/rotate_video_desc"
android:title="@string/rotate_video"
app:defaultValue="false"
android:summary="@string/rotate_video_desc"
app:key="@string/rotate_video_key" />
<SwitchPreference
android:icon="@drawable/screen_rotation"
android:summary="@string/auto_rotate_video_desc"
android:title="@string/auto_rotate_video"
app:defaultValue="false"
android:summary="@string/auto_rotate_video_desc"
app:key="@string/auto_rotate_video_key" />
<SwitchPreference
android:icon="@drawable/preview_seekbar_24"
android:summary="@string/preview_seekbar_desc"
android:title="@string/preview_seekbar"
app:defaultValue="true"
android:summary="@string/preview_seekbar_desc"
app:key="@string/preview_seekbar_key" />
<SwitchPreference
android:icon="@drawable/ic_baseline_extension_24"
android:summary="@string/software_decoding_desc"
android:title="@string/software_decoding"
app:defaultValue="true"
app:key="@string/software_decoding_key" />
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_category_gestures"
app:key="@string/pref_category_gestures_key">
Expand Down Expand Up @@ -153,8 +154,7 @@
app:showSeekBarValue="true" />
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_category_cache">
<PreferenceCategory android:title="@string/pref_category_cache">
<Preference
android:icon="@drawable/ic_baseline_storage_24"
android:key="@string/video_buffer_disk_key"
Expand All @@ -179,13 +179,13 @@
android:title="@string/video_buffer_clear_settings" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_category_android_tv"
android:key="@string/pref_category_android_tv_key" >
android:key="@string/pref_category_android_tv_key"
android:title="@string/pref_category_android_tv">
<SeekBarPreference
android:defaultValue="10"
android:max="60"
android:title="@string/android_tv_interface_on_seek_settings"
android:summary="@string/android_tv_interface_on_seek_settings_summary"
android:title="@string/android_tv_interface_on_seek_settings"
app:adjustable="true"
app:defaultValue="30"
app:icon="@drawable/go_forward_30"
Expand All @@ -196,8 +196,8 @@
<SeekBarPreference
android:defaultValue="10"
android:max="60"
android:title="@string/android_tv_interface_off_seek_settings"
android:summary="@string/android_tv_interface_off_seek_settings_summary"
android:title="@string/android_tv_interface_off_seek_settings"
app:adjustable="true"
app:defaultValue="10"
app:icon="@drawable/go_forward_30"
Expand Down

0 comments on commit 1eced92

Please sign in to comment.