From dc1ff570c174205cdc63cf364194cddf84c1eb44 Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Sun, 5 Apr 2026 13:35:42 +0530 Subject: [PATCH 01/14] Trying Auto Skip --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 86 +++++++++++++++++++ .../main/res/layout/player_custom_layout.xml | 5 +- .../res/layout/player_custom_layout_tv.xml | 5 +- .../res/values/donottranslate-strings.xml | 1 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/settings_player.xml | 8 +- 6 files changed, 103 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index ad7c8915f4b..7e0e00e4bb6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -138,6 +138,7 @@ class GeneratorPlayer : FullScreenPlayer() { const val NOTIFICATION_ID = 2326 const val CHANNEL_ID = 7340 const val STOP_ACTION = "stopcs3" + private const val SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS = 5 private var lastUsedGenerator: IGenerator? = null fun newInstance(generator: IGenerator, syncData: HashMap? = null): Bundle { @@ -1996,12 +1997,91 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onDestroyView() { + clearSkipChapterAutoClick(resetText = false) binding = null super.onDestroyView() } var skipAnimator: ValueAnimator? = null var skipIndex = 0 + private var currentTimestamp: EpisodeSkip.SkipStamp? = null + private var skipAutoClickRunnable: Runnable? = null + private var skipAutoClickSecondsRemaining: Int? = null + private var skipAutoClickIndex: Int? = null + private var skipAutoClickTimestamp: EpisodeSkip.SkipStamp? = null + + private fun isAutoSkipPopupEnabled(): Boolean { + val ctx = context ?: return true + return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean( + ctx.getString(R.string.auto_skip_popup_key), + true + ) + } + + private fun updateSkipChapterButtonText() { + val text = currentTimestamp?.let { timestamp -> + if (isAutoSkipPopupEnabled()) { + skipAutoClickSecondsRemaining?.let { seconds -> + txt(R.string.skip_chapter_countdown_format, timestamp.uiText, seconds) + } ?: timestamp.uiText + } else { + timestamp.uiText + } + } + playerBinding?.skipChapterButton?.setText(text) + } + + private fun clearSkipChapterAutoClick(resetText: Boolean = true) { + skipAutoClickRunnable?.let { runnable -> + playerBinding?.skipChapterButton?.removeCallbacks(runnable) + } + skipAutoClickRunnable = null + skipAutoClickSecondsRemaining = null + skipAutoClickIndex = null + skipAutoClickTimestamp = null + if (resetText && currentTimestamp != null) { + updateSkipChapterButtonText() + } + } + + private fun startSkipChapterAutoClick(timestamp: EpisodeSkip.SkipStamp, currentIndex: Int) { + if ( + skipAutoClickRunnable != null && + skipAutoClickIndex == currentIndex && + skipAutoClickTimestamp == timestamp + ) return + + clearSkipChapterAutoClick(resetText = false) + if (!isAutoSkipPopupEnabled()) { + updateSkipChapterButtonText() + return + } + + skipAutoClickIndex = currentIndex + skipAutoClickTimestamp = timestamp + skipAutoClickSecondsRemaining = SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS + updateSkipChapterButtonText() + + val runnable = object : Runnable { + override fun run() { + if (skipIndex != currentIndex || currentTimestamp != timestamp) return + + val nextSeconds = (skipAutoClickSecondsRemaining ?: return) - 1 + if (nextSeconds <= 0) { + clearSkipChapterAutoClick(resetText = false) + player.handleEvent(CSPlayerEvent.SkipCurrentChapter) + return + } + + skipAutoClickSecondsRemaining = nextSeconds + updateSkipChapterButtonText() + playerBinding?.skipChapterButton?.handler?.postDelayed(this, 1000) + } + } + + skipAutoClickRunnable = runnable + playerBinding?.skipChapterButton?.handler?.postDelayed(runnable, 1000) + } private fun displayTimeStamp(show: Boolean) { if (timestampShowState == show) return @@ -2053,11 +2133,14 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onTimestampSkipped(timestamp: EpisodeSkip.SkipStamp) { + currentTimestamp = null + clearSkipChapterAutoClick(resetText = false) displayTimeStamp(false) } override fun onTimestamp(timestamp: EpisodeSkip.SkipStamp?) { if (timestamp != null) { + currentTimestamp = timestamp playerBinding?.skipChapterButton?.setText(timestamp.uiText) displayTimeStamp(true) val currentIndex = skipIndex @@ -2065,7 +2148,10 @@ class GeneratorPlayer : FullScreenPlayer() { if (skipIndex == currentIndex) displayTimeStamp(false) }, 6000) + startSkipChapterAutoClick(timestamp, currentIndex) } else { + currentTimestamp = null + clearSkipChapterAutoClick(resetText = false) displayTimeStamp(false) } } diff --git a/app/src/main/res/layout/player_custom_layout.xml b/app/src/main/res/layout/player_custom_layout.xml index 72024a918d5..de6886b3d6c 100644 --- a/app/src/main/res/layout/player_custom_layout.xml +++ b/app/src/main/res/layout/player_custom_layout.xml @@ -620,11 +620,12 @@ - \ No newline at end of file + diff --git a/app/src/main/res/layout/player_custom_layout_tv.xml b/app/src/main/res/layout/player_custom_layout_tv.xml index ed06ef2b6a2..82c31dd3d6e 100644 --- a/app/src/main/res/layout/player_custom_layout_tv.xml +++ b/app/src/main/res/layout/player_custom_layout_tv.xml @@ -315,10 +315,11 @@ - \ No newline at end of file + diff --git a/app/src/main/res/values/donottranslate-strings.xml b/app/src/main/res/values/donottranslate-strings.xml index 0b7aab4cb7b..8c32243b68c 100644 --- a/app/src/main/res/values/donottranslate-strings.xml +++ b/app/src/main/res/values/donottranslate-strings.xml @@ -38,6 +38,7 @@ android_tv_interface_on_seek_key swipe_vertical_enabled_key autoplay_next_key + auto_skip_popup_key display_sub_key show_fillers_key show_player_metadata_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e9dd2748fc0..fe6a7dd042d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -156,6 +156,8 @@ Slide up or down on the left or right side to change brightness or volume Autoplay next episode Start the next episode when the current one ends + Auto-skip OP + Automatically SKIP OP after 5 seconds Double tap to seek Double tap to pause Player seek amount (Seconds) @@ -561,6 +563,7 @@ Mixed opening Credits Intro + %1$s (%2$d) Clear history History Show skip popups for opening/ending diff --git a/app/src/main/res/xml/settings_player.xml b/app/src/main/res/xml/settings_player.xml index 6e136747448..99d65719df4 100644 --- a/app/src/main/res/xml/settings_player.xml +++ b/app/src/main/res/xml/settings_player.xml @@ -98,6 +98,12 @@ android:title="@string/video_skip_op" app:defaultValue="true" app:key="@string/enable_skip_op_from_database" /> + - \ No newline at end of file + From a7a8dc11343eedff4fbcadd4675fd0373727cc8b Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Thu, 9 Apr 2026 09:23:59 +0530 Subject: [PATCH 02/14] Trying Auto Skip --- .../com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index fffc32c1a9b..71eff245e01 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -2133,6 +2133,8 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onTimestampSkipped(timestamp: VideoSkipStamp) { + currentTimestamp = null + clearSkipChapterAutoClick(resetText = false) displayTimeStamp(false) } From 3b7ce95dae06d221ad25fd1b489c5b24ff511487 Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Thu, 9 Apr 2026 09:51:03 +0530 Subject: [PATCH 03/14] Minor Fix --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 31 +++++++++---------- app/src/main/res/xml/settings_player.xml | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 71eff245e01..08e8ca73a0f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -1997,24 +1997,24 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onDestroyView() { - clearSkipChapterAutoClick(resetText = false) + clearSkipChapterAutoClick() binding = null super.onDestroyView() } var skipAnimator: ValueAnimator? = null var skipIndex = 0 - private var currentTimestamp: EpisodeSkip.SkipStamp? = null + private var currentTimestamp: VideoSkipStamp? = null private var skipAutoClickRunnable: Runnable? = null private var skipAutoClickSecondsRemaining: Int? = null private var skipAutoClickIndex: Int? = null - private var skipAutoClickTimestamp: EpisodeSkip.SkipStamp? = null + private var skipAutoClickTimestamp: VideoSkipStamp? = null private fun isAutoSkipPopupEnabled(): Boolean { - val ctx = context ?: return true + val ctx = context ?: return false return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean( ctx.getString(R.string.auto_skip_popup_key), - true + false ) } @@ -2031,27 +2031,26 @@ class GeneratorPlayer : FullScreenPlayer() { playerBinding?.skipChapterButton?.setText(text) } - private fun clearSkipChapterAutoClick(resetText: Boolean = true) { + private fun clearSkipChapterAutoClick() { + val button = playerBinding?.skipChapterButton + skipAutoClickRunnable?.let { runnable -> - playerBinding?.skipChapterButton?.removeCallbacks(runnable) + button?.removeCallbacks(runnable) } + skipAutoClickRunnable = null skipAutoClickSecondsRemaining = null skipAutoClickIndex = null skipAutoClickTimestamp = null - if (resetText && currentTimestamp != null) { - updateSkipChapterButtonText() - } } - - private fun startSkipChapterAutoClick(timestamp: EpisodeSkip.SkipStamp, currentIndex: Int) { + private fun startSkipChapterAutoClick(timestamp: VideoSkipStamp, currentIndex: Int) { if ( skipAutoClickRunnable != null && skipAutoClickIndex == currentIndex && skipAutoClickTimestamp == timestamp ) return - clearSkipChapterAutoClick(resetText = false) + clearSkipChapterAutoClick() if (!isAutoSkipPopupEnabled()) { updateSkipChapterButtonText() return @@ -2068,7 +2067,7 @@ class GeneratorPlayer : FullScreenPlayer() { val nextSeconds = (skipAutoClickSecondsRemaining ?: return) - 1 if (nextSeconds <= 0) { - clearSkipChapterAutoClick(resetText = false) + clearSkipChapterAutoClick() player.handleEvent(CSPlayerEvent.SkipCurrentChapter) return } @@ -2134,7 +2133,7 @@ class GeneratorPlayer : FullScreenPlayer() { override fun onTimestampSkipped(timestamp: VideoSkipStamp) { currentTimestamp = null - clearSkipChapterAutoClick(resetText = false) + clearSkipChapterAutoClick() displayTimeStamp(false) } @@ -2151,7 +2150,7 @@ class GeneratorPlayer : FullScreenPlayer() { startSkipChapterAutoClick(timestamp, currentIndex) } else { currentTimestamp = null - clearSkipChapterAutoClick(resetText = false) + clearSkipChapterAutoClick() displayTimeStamp(false) } } diff --git a/app/src/main/res/xml/settings_player.xml b/app/src/main/res/xml/settings_player.xml index 99d65719df4..ac197eca7f3 100644 --- a/app/src/main/res/xml/settings_player.xml +++ b/app/src/main/res/xml/settings_player.xml @@ -102,7 +102,7 @@ android:icon="@drawable/ic_baseline_skip_next_24" android:summary="@string/auto_skip_popup_settings_des" android:title="@string/auto_skip_popup_settings" - app:defaultValue="true" + app:defaultValue="false" app:key="@string/auto_skip_popup_key" /> Date: Mon, 13 Apr 2026 15:34:40 +0530 Subject: [PATCH 04/14] Minor Changes --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 74 ++++++++----------- 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 08e8ca73a0f..ee839e58b7b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -2005,10 +2005,8 @@ class GeneratorPlayer : FullScreenPlayer() { var skipAnimator: ValueAnimator? = null var skipIndex = 0 private var currentTimestamp: VideoSkipStamp? = null - private var skipAutoClickRunnable: Runnable? = null - private var skipAutoClickSecondsRemaining: Int? = null - private var skipAutoClickIndex: Int? = null - private var skipAutoClickTimestamp: VideoSkipStamp? = null + + private var skipAutoClickJob: Job? = null private fun isAutoSkipPopupEnabled(): Boolean { val ctx = context ?: return false @@ -2018,37 +2016,32 @@ class GeneratorPlayer : FullScreenPlayer() { ) } - private fun updateSkipChapterButtonText() { - val text = currentTimestamp?.let { timestamp -> - if (isAutoSkipPopupEnabled()) { - skipAutoClickSecondsRemaining?.let { seconds -> - txt(R.string.skip_chapter_countdown_format, timestamp.uiText, seconds) - } ?: timestamp.uiText + private fun updateSkipChapterButtonText( + timestamp: VideoSkipStamp? = null, + secondsRemaining: Int? = null + ) { + val displayTimestamp = timestamp ?: currentTimestamp + + val text = displayTimestamp?.let { ts -> + if (isAutoSkipPopupEnabled() && secondsRemaining != null) { + txt(R.string.skip_chapter_countdown_format, ts.uiText, secondsRemaining) } else { - timestamp.uiText + ts.uiText } } + playerBinding?.skipChapterButton?.setText(text) } private fun clearSkipChapterAutoClick() { - val button = playerBinding?.skipChapterButton - - skipAutoClickRunnable?.let { runnable -> - button?.removeCallbacks(runnable) - } - - skipAutoClickRunnable = null - skipAutoClickSecondsRemaining = null - skipAutoClickIndex = null - skipAutoClickTimestamp = null + skipAutoClickJob?.cancel() + skipAutoClickJob = null } + private fun startSkipChapterAutoClick(timestamp: VideoSkipStamp, currentIndex: Int) { - if ( - skipAutoClickRunnable != null && - skipAutoClickIndex == currentIndex && - skipAutoClickTimestamp == timestamp - ) return + if (skipAutoClickJob?.isActive == true) { + return + } clearSkipChapterAutoClick() if (!isAutoSkipPopupEnabled()) { @@ -2056,30 +2049,23 @@ class GeneratorPlayer : FullScreenPlayer() { return } - skipAutoClickIndex = currentIndex - skipAutoClickTimestamp = timestamp - skipAutoClickSecondsRemaining = SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS - updateSkipChapterButtonText() + skipAutoClickJob = viewModel.viewModelScope.launch { + try { + for (secondsRemaining in SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS downTo 1) { + if (!isActive) return@launch + if (skipIndex != currentIndex || currentTimestamp != timestamp) return@launch - val runnable = object : Runnable { - override fun run() { - if (skipIndex != currentIndex || currentTimestamp != timestamp) return + updateSkipChapterButtonText(timestamp, secondsRemaining) + delay(1000) + } - val nextSeconds = (skipAutoClickSecondsRemaining ?: return) - 1 - if (nextSeconds <= 0) { - clearSkipChapterAutoClick() + if (isActive && skipIndex == currentIndex && currentTimestamp == timestamp) { player.handleEvent(CSPlayerEvent.SkipCurrentChapter) - return } - - skipAutoClickSecondsRemaining = nextSeconds - updateSkipChapterButtonText() - playerBinding?.skipChapterButton?.handler?.postDelayed(this, 1000) + } finally { + clearSkipChapterAutoClick() } } - - skipAutoClickRunnable = runnable - playerBinding?.skipChapterButton?.handler?.postDelayed(runnable, 1000) } private fun displayTimeStamp(show: Boolean) { From fd1db6999556694fe2c4baf2c1ad99a9d6bf9944 Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Tue, 14 Apr 2026 22:03:59 +0530 Subject: [PATCH 05/14] Minor Changes --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index ee839e58b7b..83ae6b9f208 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -131,6 +131,7 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import java.io.Serializable import java.util.Calendar +import kotlin.coroutines.cancellation.CancellationException @OptIn(UnstableApi::class) class GeneratorPlayer : FullScreenPlayer() { @@ -2004,8 +2005,6 @@ class GeneratorPlayer : FullScreenPlayer() { var skipAnimator: ValueAnimator? = null var skipIndex = 0 - private var currentTimestamp: VideoSkipStamp? = null - private var skipAutoClickJob: Job? = null private fun isAutoSkipPopupEnabled(): Boolean { @@ -2017,17 +2016,13 @@ class GeneratorPlayer : FullScreenPlayer() { } private fun updateSkipChapterButtonText( - timestamp: VideoSkipStamp? = null, + timestamp: VideoSkipStamp, secondsRemaining: Int? = null ) { - val displayTimestamp = timestamp ?: currentTimestamp - - val text = displayTimestamp?.let { ts -> - if (isAutoSkipPopupEnabled() && secondsRemaining != null) { - txt(R.string.skip_chapter_countdown_format, ts.uiText, secondsRemaining) - } else { - ts.uiText - } + val text = if (isAutoSkipPopupEnabled() && secondsRemaining != null) { + txt(R.string.skip_chapter_countdown_format, timestamp.uiText, secondsRemaining) + } else { + timestamp.uiText } playerBinding?.skipChapterButton?.setText(text) @@ -2039,13 +2034,9 @@ class GeneratorPlayer : FullScreenPlayer() { } private fun startSkipChapterAutoClick(timestamp: VideoSkipStamp, currentIndex: Int) { - if (skipAutoClickJob?.isActive == true) { - return - } - clearSkipChapterAutoClick() if (!isAutoSkipPopupEnabled()) { - updateSkipChapterButtonText() + updateSkipChapterButtonText(timestamp) return } @@ -2053,17 +2044,21 @@ class GeneratorPlayer : FullScreenPlayer() { try { for (secondsRemaining in SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS downTo 1) { if (!isActive) return@launch - if (skipIndex != currentIndex || currentTimestamp != timestamp) return@launch + if (skipIndex != currentIndex) return@launch updateSkipChapterButtonText(timestamp, secondsRemaining) delay(1000) } - if (isActive && skipIndex == currentIndex && currentTimestamp == timestamp) { + if (isActive && skipIndex == currentIndex) { player.handleEvent(CSPlayerEvent.SkipCurrentChapter) } + } catch (e: CancellationException) { + throw e } finally { - clearSkipChapterAutoClick() + if (isActive) { + clearSkipChapterAutoClick() + } } } } @@ -2075,16 +2070,12 @@ class GeneratorPlayer : FullScreenPlayer() { playerBinding?.skipChapterButton?.apply { val showWidth = 170.toPx val noShowWidth = 10.toPx - //if((show && width == showWidth) || (!show && width == noShowWidth)) { - // return - //} val to = if (show) showWidth else noShowWidth val from = if (!show) showWidth else noShowWidth skipAnimator?.cancel() isVisible = true - // just in case val lay = layoutParams lay.width = from layoutParams = lay @@ -2094,13 +2085,11 @@ class GeneratorPlayer : FullScreenPlayer() { addListener(onEnd = { if (show) { if (!isShowing) { - // Automatically request focus if the menu is not opened playerBinding?.skipChapterButton?.requestFocus() } } else { playerBinding?.skipChapterButton?.isVisible = false if (!isShowing) { - // Automatically return focus to play pause playerBinding?.playerPausePlay?.requestFocus() } } @@ -2118,14 +2107,12 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onTimestampSkipped(timestamp: VideoSkipStamp) { - currentTimestamp = null clearSkipChapterAutoClick() displayTimeStamp(false) } override fun onTimestamp(timestamp: VideoSkipStamp?) { if (timestamp != null) { - currentTimestamp = timestamp playerBinding?.skipChapterButton?.setText(timestamp.uiText) displayTimeStamp(true) val currentIndex = skipIndex @@ -2135,7 +2122,6 @@ class GeneratorPlayer : FullScreenPlayer() { }, 6000) startSkipChapterAutoClick(timestamp, currentIndex) } else { - currentTimestamp = null clearSkipChapterAutoClick() displayTimeStamp(false) } From 409d6151edfe53f9fc2426d1ae76950632c76061 Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Thu, 16 Apr 2026 20:37:09 +0530 Subject: [PATCH 06/14] Minor Changes --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 83ae6b9f208..b0d424ab481 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -67,6 +67,7 @@ import com.lagradost.cloudstream3.isEpisodeBased import com.lagradost.cloudstream3.isLiveStream import com.lagradost.cloudstream3.isMovieType import com.lagradost.cloudstream3.mvvm.Resource +import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observeNullable @@ -2040,11 +2041,11 @@ class GeneratorPlayer : FullScreenPlayer() { return } - skipAutoClickJob = viewModel.viewModelScope.launch { + skipAutoClickJob = viewModel.viewModelScope.launchSafe { try { for (secondsRemaining in SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS downTo 1) { - if (!isActive) return@launch - if (skipIndex != currentIndex) return@launch + if (!isActive) return@launchSafe + if (skipIndex != currentIndex) return@launchSafe updateSkipChapterButtonText(timestamp, secondsRemaining) delay(1000) @@ -2053,8 +2054,8 @@ class GeneratorPlayer : FullScreenPlayer() { if (isActive && skipIndex == currentIndex) { player.handleEvent(CSPlayerEvent.SkipCurrentChapter) } - } catch (e: CancellationException) { - throw e + } catch (_: CancellationException) { + // If we get canceled, do nothing. } finally { if (isActive) { clearSkipChapterAutoClick() @@ -2085,6 +2086,7 @@ class GeneratorPlayer : FullScreenPlayer() { addListener(onEnd = { if (show) { if (!isShowing) { + // Automatically request focus if the menu is not opened playerBinding?.skipChapterButton?.requestFocus() } } else { From 5bbd18a77e4a6fb8422221b8dce83893c73d3da8 Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Thu, 16 Apr 2026 20:38:58 +0530 Subject: [PATCH 07/14] Minor Changes --- .../com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index b0d424ab481..4ffa8f27d52 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -2085,8 +2085,8 @@ class GeneratorPlayer : FullScreenPlayer() { ).apply { addListener(onEnd = { if (show) { + // Automatically request focus if the menu is not opened if (!isShowing) { - // Automatically request focus if the menu is not opened playerBinding?.skipChapterButton?.requestFocus() } } else { From 8add6fbebb6130b1f8bfd8f64805dd690394afee Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Thu, 16 Apr 2026 20:39:53 +0530 Subject: [PATCH 08/14] Minor Changes --- .../com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 4ffa8f27d52..b0d424ab481 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -2085,8 +2085,8 @@ class GeneratorPlayer : FullScreenPlayer() { ).apply { addListener(onEnd = { if (show) { - // Automatically request focus if the menu is not opened if (!isShowing) { + // Automatically request focus if the menu is not opened playerBinding?.skipChapterButton?.requestFocus() } } else { From 922332064f3b182bab12bfc32f5be880cc225e18 Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Thu, 16 Apr 2026 20:40:48 +0530 Subject: [PATCH 09/14] Minor Changes --- .../com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index b0d424ab481..6fa38b1901b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -2071,12 +2071,16 @@ class GeneratorPlayer : FullScreenPlayer() { playerBinding?.skipChapterButton?.apply { val showWidth = 170.toPx val noShowWidth = 10.toPx + //if((show && width == showWidth) || (!show && width == noShowWidth)) { + // return + //} val to = if (show) showWidth else noShowWidth val from = if (!show) showWidth else noShowWidth skipAnimator?.cancel() isVisible = true + // just in case val lay = layoutParams lay.width = from layoutParams = lay From 9963802d94dd74b568facea35775725482b79e9c Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Sun, 1 Nov 2026 10:30:28 +0530 Subject: [PATCH 10/14] Make the auto-skip countdown cancellable - Any tap, swipe or key press now cancels the countdown, giving the user manual control (per review feedback) - Cancel the countdown when playback is paused so the player never seeks away on its own while paused - Restore the plain skip label whenever the countdown ends or is cancelled instead of leaving a stale '(3)' on the button - Run the countdown in viewLifecycleOwner.lifecycleScope so it is cancelled with the view; removes the onDestroyView override and the redundant try/catch/finally - Revert the ineffective skip button width change (the show/hide animator always sets its own width); keep the ellipsize fix - Reword the setting title/description to match what it does --- .../ui/player/FullScreenPlayer.kt | 13 +++ .../cloudstream3/ui/player/GeneratorPlayer.kt | 83 +++++++++---------- .../main/res/layout/player_custom_layout.xml | 2 +- .../res/layout/player_custom_layout_tv.xml | 2 +- 4 files changed, 55 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index d337d53a6c9..629e860849d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -1093,11 +1093,20 @@ open class FullScreenPlayer : AbstractPlayerFragment( override fun isUIShowing(): Boolean = isShowing + /** + * Called whenever the user interacts with the player while it is active + * (tap, swipe or key press). Lets subclasses abort automatic actions + * such as the auto-skip countdown. + */ + protected open fun onPlayerInteraction() {} + override fun onSingleTap() { + onPlayerInteraction() onClickChange() } override fun onTouchDown() { + onPlayerInteraction() if (isShowingEpisodeOverlay) toggleEpisodesOverlay(show = false) } @@ -1294,6 +1303,10 @@ open class FullScreenPlayer : AbstractPlayerFragment( } private fun handleKeyEvent(event: KeyEvent, hasNavigated: Boolean): Boolean { + if (event.action == KeyEvent.ACTION_DOWN) { + onPlayerInteraction() + } + if (hasNavigated) { autoHide() return false diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index a30b409813d..82970089480 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -34,6 +34,7 @@ import androidx.core.text.toSpanned import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope import androidx.lifecycle.viewModelScope import androidx.media3.common.Format.NO_VALUE import androidx.media3.common.MimeTypes @@ -68,7 +69,6 @@ import com.lagradost.cloudstream3.isEpisodeBased import com.lagradost.cloudstream3.isLiveStream import com.lagradost.cloudstream3.isMovieType import com.lagradost.cloudstream3.mvvm.Resource -import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observeNullable @@ -138,7 +138,6 @@ import kotlinx.coroutines.launch import java.io.Serializable import java.lang.ref.WeakReference import java.util.Calendar -import kotlin.coroutines.cancellation.CancellationException import java.util.UUID import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.atomic.AtomicBoolean @@ -241,6 +240,9 @@ class GeneratorPlayer : FullScreenPlayer() { super.playerStatusChanged() if (player.getIsPlaying()) { viewModel.forceClearCache = false + } else if (currentPlayerStatus == CSPlayerLoading.IsPaused) { + // Never seek away while the user has paused the video + cancelAutoSkipCountdown() } } @@ -2056,11 +2058,6 @@ class GeneratorPlayer : FullScreenPlayer() { } } - override fun onDestroyView() { - clearSkipChapterAutoClick() - super.onDestroyView() - } - /** * This is used instead of layout-television to follow the * settings and some TV devices are not classified as TV @@ -2071,9 +2068,9 @@ class GeneratorPlayer : FullScreenPlayer() { var skipAnimator: ValueAnimator? = null var skipIndex = 0 - private var skipAutoClickJob: Job? = null + private var autoSkipJob: Job? = null - private fun isAutoSkipPopupEnabled(): Boolean { + private fun isAutoSkipEnabled(): Boolean { val ctx = context ?: return false return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean( ctx.getString(R.string.auto_skip_popup_key), @@ -2081,54 +2078,53 @@ class GeneratorPlayer : FullScreenPlayer() { ) } - private fun updateSkipChapterButtonText( - timestamp: VideoSkipStamp, - secondsRemaining: Int? = null - ) { - val text = if (isAutoSkipPopupEnabled() && secondsRemaining != null) { - txt(R.string.skip_chapter_countdown_format, timestamp.uiText, secondsRemaining) - } else { - timestamp.uiText - } - - playerBinding?.skipChapterButton?.setText(text) - } - - private fun clearSkipChapterAutoClick() { - skipAutoClickJob?.cancel() - skipAutoClickJob = null + private fun cancelAutoSkipCountdown() { + autoSkipJob?.cancel() + autoSkipJob = null } - private fun startSkipChapterAutoClick(timestamp: VideoSkipStamp, currentIndex: Int) { - clearSkipChapterAutoClick() - if (!isAutoSkipPopupEnabled()) { - updateSkipChapterButtonText(timestamp) - return - } + /** + * Counts down on the skip button and skips the chapter once it reaches + * zero. The countdown is cancelled by any user interaction (see + * [onPlayerInteraction]) or when the player is paused, so the user + * always keeps manual control. + */ + private fun startAutoSkipCountdown(timestamp: VideoSkipStamp, currentIndex: Int) { + cancelAutoSkipCountdown() + if (!isAutoSkipEnabled()) return - skipAutoClickJob = viewModel.viewModelScope.launchSafe { + autoSkipJob = viewLifecycleOwner.lifecycleScope.launch { try { for (secondsRemaining in SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS downTo 1) { - if (!isActive) return@launchSafe - if (skipIndex != currentIndex) return@launchSafe + if (skipIndex != currentIndex) return@launch - updateSkipChapterButtonText(timestamp, secondsRemaining) + playerBinding?.skipChapterButton?.setText( + txt( + R.string.skip_chapter_countdown_format, + timestamp.uiText, + secondsRemaining + ) + ) delay(1000) } - if (isActive && skipIndex == currentIndex) { + if (skipIndex == currentIndex) { player.handleEvent(CSPlayerEvent.SkipCurrentChapter) } - } catch (_: CancellationException) { - // If we get canceled, do nothing. } finally { - if (isActive) { - clearSkipChapterAutoClick() + // Restore the plain label no matter how the countdown ended + // (fired, cancelled or replaced by a new timestamp) + if (skipIndex == currentIndex) { + playerBinding?.skipChapterButton?.setText(timestamp.uiText) } } } } + override fun onPlayerInteraction() { + cancelAutoSkipCountdown() + } + private fun displayTimeStamp(show: Boolean) { if (timestampShowState == show) return skipIndex++ @@ -2162,6 +2158,7 @@ class GeneratorPlayer : FullScreenPlayer() { if (!show) { playerBinding?.skipChapterButton?.isVisible = false if (!isShowing) { + // Automatically return focus to play pause playerBinding?.playerPausePlay?.requestFocus() } } @@ -2179,7 +2176,7 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onTimestampSkipped(timestamp: VideoSkipStamp) { - clearSkipChapterAutoClick() + cancelAutoSkipCountdown() displayTimeStamp(false) } @@ -2192,9 +2189,9 @@ class GeneratorPlayer : FullScreenPlayer() { if (skipIndex == currentIndex) displayTimeStamp(false) }, 6000) - startSkipChapterAutoClick(timestamp, currentIndex) + startAutoSkipCountdown(timestamp, currentIndex) } else { - clearSkipChapterAutoClick() + cancelAutoSkipCountdown() displayTimeStamp(false) } } diff --git a/app/src/main/res/layout/player_custom_layout.xml b/app/src/main/res/layout/player_custom_layout.xml index 6c2a60d8bbb..76c499377a0 100644 --- a/app/src/main/res/layout/player_custom_layout.xml +++ b/app/src/main/res/layout/player_custom_layout.xml @@ -630,7 +630,7 @@ Date: Sun, 1 Nov 2026 10:41:05 +0530 Subject: [PATCH 11/14] Add undo snackbar, configurable countdown, per-type auto-skip and skip margin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Show a 'Skipped — Undo' snackbar after an automatic skip so inaccurate timestamps are recoverable; undo seeks back and suppresses auto-skipping that same timestamp again - New 'Auto-skip countdown (Seconds)' setting (0-10, default 5); 0 skips instantly, covering both behaviours requested in review - New 'Auto-skip types' setting with a multi-select dialog so users can e.g. auto-skip openings but never endings; defaults to all types - Both new preferences depend on the Auto skip switch and are disabled while it is off - Seek 500ms past the timestamp end when skipping a chapter so the last frames of the skipped section are not shown --- .../cloudstream3/ui/player/CS3IPlayer.kt | 5 +- .../cloudstream3/ui/player/GeneratorPlayer.kt | 72 ++++++++++++++++--- .../ui/settings/SettingsPlayer.kt | 24 +++++++ .../res/values/donottranslate-strings.xml | 3 + app/src/main/res/values/strings.xml | 8 ++- app/src/main/res/xml/settings_player.xml | 19 +++++ 6 files changed, 121 insertions(+), 10 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 b63191c19a9..ed0643a0601 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 @@ -670,6 +670,7 @@ class CS3IPlayer : IPlayer { companion object { private const val CRONET_TIMEOUT_MS = 15_000 + private const val SKIP_CHAPTER_END_MARGIN_MS = 500L /** * Single shared engine, to minimize the overhead of maintaining many as: @@ -1025,7 +1026,9 @@ class CS3IPlayer : IPlayer { if (lastTimeStamp.skipToNextEpisode) { handleEvent(CSPlayerEvent.NextEpisode, source) } else { - seekTo(lastTimeStamp.timestamp.endMs + 1L) + // A small margin past the end so the last frames + // of the skipped section are not shown + seekTo(lastTimeStamp.timestamp.endMs + SKIP_CHAPTER_END_MARGIN_MS) } event(TimestampSkippedEvent(timestamp = lastTimeStamp, source = source)) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 82970089480..bd0df768c8f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -114,6 +114,7 @@ import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLinkType import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog +import com.lagradost.cloudstream3.utils.SnackbarHelper import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToEnglishLanguageName import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToLanguageName import com.lagradost.cloudstream3.utils.SubtitleHelper.languages @@ -148,7 +149,8 @@ class GeneratorPlayer : FullScreenPlayer() { const val NOTIFICATION_ID = 2326 const val CHANNEL_ID = 7340 const val STOP_ACTION = "stopcs3" - private const val SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS = 5 + private const val DEFAULT_AUTO_SKIP_COUNTDOWN_SECONDS = 5 + private const val AUTO_SKIP_UNDO_DURATION_MS = 4000 private val generators = ConcurrentHashMap>() fun newInstance( @@ -2070,11 +2072,30 @@ class GeneratorPlayer : FullScreenPlayer() { var skipIndex = 0 private var autoSkipJob: Job? = null - private fun isAutoSkipEnabled(): Boolean { + /** Timestamp the user rolled back with undo, never auto-skip it again */ + private var undoneTimestamp: VideoSkipStamp? = null + + private fun isAutoSkipEnabled(timestamp: VideoSkipStamp): Boolean { val ctx = context ?: return false - return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean( - ctx.getString(R.string.auto_skip_popup_key), - false + val prefs = PreferenceManager.getDefaultSharedPreferences(ctx) + if (!prefs.getBoolean(ctx.getString(R.string.auto_skip_popup_key), false)) { + return false + } + + // The user can exclude individual skip types from auto skipping + val disabledTypes = prefs.getStringSet( + ctx.getString(R.string.auto_skip_disabled_types_key), + emptySet() + ).orEmpty() + + return timestamp.timestamp.type.name !in disabledTypes + } + + private fun getAutoSkipCountdownSeconds(): Int { + val ctx = context ?: return DEFAULT_AUTO_SKIP_COUNTDOWN_SECONDS + return PreferenceManager.getDefaultSharedPreferences(ctx).getInt( + ctx.getString(R.string.auto_skip_countdown_key), + DEFAULT_AUTO_SKIP_COUNTDOWN_SECONDS ) } @@ -2083,6 +2104,32 @@ class GeneratorPlayer : FullScreenPlayer() { autoSkipJob = null } + /** + * Skips the current chapter and offers a short undo window, since skip + * timestamps are not always accurate. + */ + private fun autoSkipChapter(timestamp: VideoSkipStamp) { + // Skipping to the next episode cannot be undone with a simple seek + if (!timestamp.skipToNextEpisode) { + val skippedName = + txt(timestamp.timestamp.label ?: getString(timestamp.timestamp.type.res)) + + player.getPosition()?.let { position -> + SnackbarHelper.showSnackbar( + activity, + txt(R.string.skipped_type_format, skippedName), + AUTO_SKIP_UNDO_DURATION_MS, + txt(R.string.undo) + ) { + undoneTimestamp = timestamp + player.seekTo(position) + } + } + } + + player.handleEvent(CSPlayerEvent.SkipCurrentChapter) + } + /** * Counts down on the skip button and skips the chapter once it reaches * zero. The countdown is cancelled by any user interaction (see @@ -2091,11 +2138,20 @@ class GeneratorPlayer : FullScreenPlayer() { */ private fun startAutoSkipCountdown(timestamp: VideoSkipStamp, currentIndex: Int) { cancelAutoSkipCountdown() - if (!isAutoSkipEnabled()) return + if (!isAutoSkipEnabled(timestamp)) return + if (timestamp == undoneTimestamp) return + undoneTimestamp = null + + val countdownSeconds = getAutoSkipCountdownSeconds() + if (countdownSeconds <= 0) { + // Skip instantly when the countdown is set to zero + autoSkipChapter(timestamp) + return + } autoSkipJob = viewLifecycleOwner.lifecycleScope.launch { try { - for (secondsRemaining in SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS downTo 1) { + for (secondsRemaining in countdownSeconds downTo 1) { if (skipIndex != currentIndex) return@launch playerBinding?.skipChapterButton?.setText( @@ -2109,7 +2165,7 @@ class GeneratorPlayer : FullScreenPlayer() { } if (skipIndex == currentIndex) { - player.handleEvent(CSPlayerEvent.SkipCurrentChapter) + autoSkipChapter(timestamp) } } finally { // Restore the plain label no matter how the countdown ended diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt index 2949281153f..319426675a9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt @@ -28,6 +28,7 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard +import com.lagradost.cloudstream3.utils.videoskip.SkipType class SettingsPlayer : BasePreferenceFragmentCompat() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -150,6 +151,29 @@ class SettingsPlayer : BasePreferenceFragmentCompat() { true } + getPref(R.string.auto_skip_types_key)?.setOnPreferenceClickListener { + val types = SkipType.entries + val disabledKey = getString(R.string.auto_skip_disabled_types_key) + val disabled = settingsManager.getStringSet(disabledKey, emptySet()).orEmpty() + + activity?.showMultiDialog( + types.map { getString(it.res) }, + types.indices.filter { types[it].name !in disabled }, + getString(R.string.auto_skip_types_settings), + {} + ) { selected -> + val selectedNames = selected.map { types[it].name }.toSet() + settingsManager.edit { + putStringSet( + disabledKey, + types.map { it.name }.filter { it !in selectedNames }.toSet() + ) + } + } + + true + } + getPref(R.string.hide_player_control_names_key)?.hideOn(TV) getPref(R.string.quality_pref_key)?.setOnPreferenceClickListener { diff --git a/app/src/main/res/values/donottranslate-strings.xml b/app/src/main/res/values/donottranslate-strings.xml index 73e5aebc047..b8d9825d4c7 100644 --- a/app/src/main/res/values/donottranslate-strings.xml +++ b/app/src/main/res/values/donottranslate-strings.xml @@ -40,6 +40,9 @@ swipe_vertical_enabled_key autoplay_next_key auto_skip_popup_key + auto_skip_countdown_key + auto_skip_types_key + auto_skip_disabled_types_key display_sub_key show_fillers_key show_player_metadata_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9bf93228c2e..3d0887c377d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -159,7 +159,11 @@ Autoplay next episode Start the next episode when the current one ends Auto skip - Automatically skip openings and endings after a 5 second countdown. Cancel by tapping the screen or pressing any key. + Automatically skip openings and endings after a countdown. Cancel by tapping the screen or pressing any key. + Auto-skip countdown (Seconds) + How long to wait before automatically skipping. Set to 0 to skip instantly + Auto-skip types + Choose which timestamps are automatically skipped Start videos paused Reduce stress when selecting sources Double tap to seek @@ -585,6 +589,8 @@ Preview Intro %1$s (%2$d) + Skipped %1$s + Undo Clear history History Show skip popups for opening/ending diff --git a/app/src/main/res/xml/settings_player.xml b/app/src/main/res/xml/settings_player.xml index 9ff11d615f5..6fb216a516d 100644 --- a/app/src/main/res/xml/settings_player.xml +++ b/app/src/main/res/xml/settings_player.xml @@ -110,6 +110,25 @@ android:title="@string/auto_skip_popup_settings" app:defaultValue="false" app:key="@string/auto_skip_popup_key" /> + + Date: Sun, 1 Nov 2026 10:49:59 +0530 Subject: [PATCH 12/14] Fix auto-skip countdown restarting on every buffering/seek event The player re-invokes the current timestamp on buffering transitions, seeks and stamp loading, which reset the button label and restarted the countdown from scratch each time. On streams that buffer at the start of a video this meant the countdown never completed and the button only ever showed the plain 'Skip Opening' label. - Ignore re-invokes of a timestamp that is already showing - Remember a timestamp the user declined by interacting or pausing, so a later re-show does not start a new countdown and skip anyway --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index bd0df768c8f..96ffeb44ee2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -245,6 +245,7 @@ class GeneratorPlayer : FullScreenPlayer() { } else if (currentPlayerStatus == CSPlayerLoading.IsPaused) { // Never seek away while the user has paused the video cancelAutoSkipCountdown() + declinedTimestamp = shownTimestamp } } @@ -2072,8 +2073,11 @@ class GeneratorPlayer : FullScreenPlayer() { var skipIndex = 0 private var autoSkipJob: Job? = null - /** Timestamp the user rolled back with undo, never auto-skip it again */ - private var undoneTimestamp: VideoSkipStamp? = null + /** + * Timestamp the user declined, either by interacting with the player + * during its countdown or by undoing its skip. Never auto-skip it again. + */ + private var declinedTimestamp: VideoSkipStamp? = null private fun isAutoSkipEnabled(timestamp: VideoSkipStamp): Boolean { val ctx = context ?: return false @@ -2121,7 +2125,7 @@ class GeneratorPlayer : FullScreenPlayer() { AUTO_SKIP_UNDO_DURATION_MS, txt(R.string.undo) ) { - undoneTimestamp = timestamp + declinedTimestamp = timestamp player.seekTo(position) } } @@ -2139,8 +2143,8 @@ class GeneratorPlayer : FullScreenPlayer() { private fun startAutoSkipCountdown(timestamp: VideoSkipStamp, currentIndex: Int) { cancelAutoSkipCountdown() if (!isAutoSkipEnabled(timestamp)) return - if (timestamp == undoneTimestamp) return - undoneTimestamp = null + if (timestamp == declinedTimestamp) return + declinedTimestamp = null val countdownSeconds = getAutoSkipCountdownSeconds() if (countdownSeconds <= 0) { @@ -2178,7 +2182,10 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onPlayerInteraction() { + // The user wants manual control: stop the countdown and never + // auto-skip the currently shown timestamp again cancelAutoSkipCountdown() + declinedTimestamp = shownTimestamp } private fun displayTimeStamp(show: Boolean) { @@ -2236,8 +2243,17 @@ class GeneratorPlayer : FullScreenPlayer() { displayTimeStamp(false) } + /** Timestamp currently shown on the skip button */ + private var shownTimestamp: VideoSkipStamp? = null + override fun onTimestamp(timestamp: VideoSkipStamp?) { if (timestamp != null) { + // The player re-invokes the current timestamp on seeks and + // buffering transitions, so ignore it while the skip button is + // already showing it, otherwise the countdown restarts endlessly + if (timestamp == shownTimestamp && timestampShowState) return + + shownTimestamp = timestamp playerBinding?.skipChapterButton?.setText(timestamp.uiText) displayTimeStamp(true) val currentIndex = skipIndex @@ -2247,6 +2263,7 @@ class GeneratorPlayer : FullScreenPlayer() { }, 6000) startAutoSkipCountdown(timestamp, currentIndex) } else { + shownTimestamp = null cancelAutoSkipCountdown() displayTimeStamp(false) } From 4e5631a7da3a49e3166841dadc54bead6efd679a Mon Sep 17 00:00:00 2001 From: Phisher98 Date: Sun, 1 Nov 2026 11:06:32 +0530 Subject: [PATCH 13/14] Move auto-skip settings into the Compose player settings and drop the undo snackbar The legacy XML preferences screen (settings_player.xml) is no longer reachable; the live Player settings are the Compose SettingsPlayerScreen, so the auto-skip settings were invisible. Add them there instead: - 'Auto skip' switch under 'Skip OP' - 'Auto-skip countdown (Seconds)' slider (0-10), disabled while off - 'Auto-skip types' multi-select, disabled while off, defaults to all Also remove the 'Skipped ... Undo' snackbar per feedback; the countdown can be cancelled by interacting with the player, and a wrong skip can be undone by seeking back manually --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 47 ++++--------------- .../ui/settings/SettingsPlayer.kt | 24 ---------- .../ui/settings/SettingsPlayerScreen.kt | 25 ++++++++++ .../res/values/donottranslate-strings.xml | 1 - app/src/main/res/values/strings.xml | 3 -- app/src/main/res/xml/settings_player.xml | 19 -------- .../cloudstream4/DevicePreferenceStore.kt | 10 ++++ 7 files changed, 45 insertions(+), 84 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 96ffeb44ee2..8d1491a8427 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -114,7 +114,6 @@ import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLinkType import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog -import com.lagradost.cloudstream3.utils.SnackbarHelper import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToEnglishLanguageName import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToLanguageName import com.lagradost.cloudstream3.utils.SubtitleHelper.languages @@ -130,6 +129,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.toPx import com.lagradost.cloudstream3.utils.downloader.DownloadUtils.getImageBitmapFromUrl import com.lagradost.cloudstream3.utils.setText import com.lagradost.cloudstream3.utils.txt +import com.lagradost.cloudstream3.utils.videoskip.SkipType import com.lagradost.cloudstream3.utils.videoskip.VideoSkipStamp import com.lagradost.safefile.SafeFile import kotlinx.coroutines.Job @@ -150,7 +150,6 @@ class GeneratorPlayer : FullScreenPlayer() { const val CHANNEL_ID = 7340 const val STOP_ACTION = "stopcs3" private const val DEFAULT_AUTO_SKIP_COUNTDOWN_SECONDS = 5 - private const val AUTO_SKIP_UNDO_DURATION_MS = 4000 private val generators = ConcurrentHashMap>() fun newInstance( @@ -2074,8 +2073,8 @@ class GeneratorPlayer : FullScreenPlayer() { private var autoSkipJob: Job? = null /** - * Timestamp the user declined, either by interacting with the player - * during its countdown or by undoing its skip. Never auto-skip it again. + * Timestamp the user declined by interacting with the player during its + * countdown. Never auto-skip it again. */ private var declinedTimestamp: VideoSkipStamp? = null @@ -2086,13 +2085,13 @@ class GeneratorPlayer : FullScreenPlayer() { return false } - // The user can exclude individual skip types from auto skipping - val disabledTypes = prefs.getStringSet( - ctx.getString(R.string.auto_skip_disabled_types_key), - emptySet() + // The user can select which skip types are automatically skipped + val enabledTypes = prefs.getStringSet( + ctx.getString(R.string.auto_skip_types_key), + SkipType.entries.map { it.name }.toSet() ).orEmpty() - return timestamp.timestamp.type.name !in disabledTypes + return timestamp.timestamp.type.name in enabledTypes } private fun getAutoSkipCountdownSeconds(): Int { @@ -2108,32 +2107,6 @@ class GeneratorPlayer : FullScreenPlayer() { autoSkipJob = null } - /** - * Skips the current chapter and offers a short undo window, since skip - * timestamps are not always accurate. - */ - private fun autoSkipChapter(timestamp: VideoSkipStamp) { - // Skipping to the next episode cannot be undone with a simple seek - if (!timestamp.skipToNextEpisode) { - val skippedName = - txt(timestamp.timestamp.label ?: getString(timestamp.timestamp.type.res)) - - player.getPosition()?.let { position -> - SnackbarHelper.showSnackbar( - activity, - txt(R.string.skipped_type_format, skippedName), - AUTO_SKIP_UNDO_DURATION_MS, - txt(R.string.undo) - ) { - declinedTimestamp = timestamp - player.seekTo(position) - } - } - } - - player.handleEvent(CSPlayerEvent.SkipCurrentChapter) - } - /** * Counts down on the skip button and skips the chapter once it reaches * zero. The countdown is cancelled by any user interaction (see @@ -2149,7 +2122,7 @@ class GeneratorPlayer : FullScreenPlayer() { val countdownSeconds = getAutoSkipCountdownSeconds() if (countdownSeconds <= 0) { // Skip instantly when the countdown is set to zero - autoSkipChapter(timestamp) + player.handleEvent(CSPlayerEvent.SkipCurrentChapter) return } @@ -2169,7 +2142,7 @@ class GeneratorPlayer : FullScreenPlayer() { } if (skipIndex == currentIndex) { - autoSkipChapter(timestamp) + player.handleEvent(CSPlayerEvent.SkipCurrentChapter) } } finally { // Restore the plain label no matter how the countdown ended diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt index 319426675a9..2949281153f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayer.kt @@ -28,7 +28,6 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard -import com.lagradost.cloudstream3.utils.videoskip.SkipType class SettingsPlayer : BasePreferenceFragmentCompat() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -151,29 +150,6 @@ class SettingsPlayer : BasePreferenceFragmentCompat() { true } - getPref(R.string.auto_skip_types_key)?.setOnPreferenceClickListener { - val types = SkipType.entries - val disabledKey = getString(R.string.auto_skip_disabled_types_key) - val disabled = settingsManager.getStringSet(disabledKey, emptySet()).orEmpty() - - activity?.showMultiDialog( - types.map { getString(it.res) }, - types.indices.filter { types[it].name !in disabled }, - getString(R.string.auto_skip_types_settings), - {} - ) { selected -> - val selectedNames = selected.map { types[it].name }.toSet() - settingsManager.edit { - putStringSet( - disabledKey, - types.map { it.name }.filter { it !in selectedNames }.toSet() - ) - } - } - - true - } - getPref(R.string.hide_player_control_names_key)?.hideOn(TV) getPref(R.string.quality_pref_key)?.setOnPreferenceClickListener { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt index 8f6f5bf4f12..9b3ab7072f9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt @@ -21,6 +21,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getFold import com.lagradost.cloudstream3.ui.subtitles.ChromecastSubtitlesFragment import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment import com.lagradost.cloudstream3.utils.Coroutines.ioSafe +import com.lagradost.cloudstream3.utils.videoskip.SkipType import com.lagradost.cloudstream4.compose.EMULATOR import com.lagradost.cloudstream4.compose.PHONE import com.lagradost.cloudstream4.compose.TV @@ -28,6 +29,7 @@ import com.lagradost.cloudstream4.compose.isLayout import com.lagradost.cloudstream4.rememberAppSettings import com.mihon.presentation.settings.Preference import com.mihon.presentation.settings.SearchableSettings +import com.mihon.presentation.settings.collectAsState import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -60,6 +62,8 @@ object SettingsPlayerScreen : SearchableSettings { } } + val autoSkipEnabled by settings.player.autoSkipEnabled.collectAsState() + return persistentListOf( Preference.PreferenceGroup( title = stringResource(R.string.pref_category_subtitles), @@ -160,6 +164,27 @@ object SettingsPlayerScreen : SearchableSettings { subtitle = stringResource(R.string.enable_skip_op_from_database_des), icon = painterResource(R.drawable.keyboard_double_arrow_right_24px), ), + Preference.PreferenceItem.SwitchPreference( + preference = settings.player.autoSkipEnabled, + title = stringResource(R.string.auto_skip_popup_settings), + subtitle = stringResource(R.string.auto_skip_popup_settings_des), + icon = painterResource(R.drawable.skip_next_24px), + ), + Preference.PreferenceItem.SliderPreference( + preference = settings.player.autoSkipCountdown, + title = stringResource(R.string.auto_skip_countdown_settings), + subtitle = stringResource(R.string.auto_skip_countdown_settings_des), + icon = painterResource(R.drawable.hourglass_24), + valueRange = 0..10, + enabled = autoSkipEnabled, + ), + Preference.PreferenceItem.MultiSelectListPreference( + preference = settings.player.autoSkipTypes, + title = stringResource(R.string.auto_skip_types_settings), + icon = painterResource(R.drawable.filter_alt_24px), + entries = SkipType.entries.associate { it.name to stringResource(it.res) }, + enabled = autoSkipEnabled, + ), Preference.PreferenceItem.SwitchPreference( preference = settings.player.autoRotateEnabled, title = stringResource(R.string.auto_rotate_video), diff --git a/app/src/main/res/values/donottranslate-strings.xml b/app/src/main/res/values/donottranslate-strings.xml index b8d9825d4c7..267e4b0b347 100644 --- a/app/src/main/res/values/donottranslate-strings.xml +++ b/app/src/main/res/values/donottranslate-strings.xml @@ -42,7 +42,6 @@ auto_skip_popup_key auto_skip_countdown_key auto_skip_types_key - auto_skip_disabled_types_key display_sub_key show_fillers_key show_player_metadata_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d0887c377d..1922713b57e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -163,7 +163,6 @@ Auto-skip countdown (Seconds) How long to wait before automatically skipping. Set to 0 to skip instantly Auto-skip types - Choose which timestamps are automatically skipped Start videos paused Reduce stress when selecting sources Double tap to seek @@ -589,8 +588,6 @@ Preview Intro %1$s (%2$d) - Skipped %1$s - Undo Clear history History Show skip popups for opening/ending diff --git a/app/src/main/res/xml/settings_player.xml b/app/src/main/res/xml/settings_player.xml index 6fb216a516d..9ff11d615f5 100644 --- a/app/src/main/res/xml/settings_player.xml +++ b/app/src/main/res/xml/settings_player.xml @@ -110,25 +110,6 @@ android:title="@string/auto_skip_popup_settings" app:defaultValue="false" app:key="@string/auto_skip_popup_key" /> - - Date: Sun, 15 Nov 2026 10:53:39 +0530 Subject: [PATCH 14/14] Trying --- .../ui/player/FullScreenPlayer.kt | 25 +++- .../cloudstream3/ui/player/GeneratorPlayer.kt | 112 +++++++++++++++--- .../cloudstream3/ui/player/PlayerView.kt | 9 +- 3 files changed, 128 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index 629e860849d..d3126edacf5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -238,10 +238,12 @@ open class FullScreenPlayer : AbstractPlayerFragment( } open fun showMirrorsDialogue() { + onPlayerInteraction() throw NotImplementedError() } open fun showTracksDialogue() { + onPlayerInteraction() throw NotImplementedError() } @@ -250,10 +252,12 @@ open class FullScreenPlayer : AbstractPlayerFragment( loadResponse: LoadResponse?, dismissCallback: (() -> Unit) ) { + onPlayerInteraction() throw NotImplementedError() } open fun showEpisodesOverlay() { + onPlayerInteraction() throw NotImplementedError() } @@ -508,6 +512,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( } private fun showSubtitleOffsetDialog() { + onPlayerInteraction() val ctx = context ?: return // Pause player because the subtitles cannot be continuously updated to follow playback. player.handleEvent( @@ -644,6 +649,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( } private fun showSpeedDialog() { + onPlayerInteraction() val act = activity ?: return val isPlaying = player.getIsPlaying() player.handleEvent(CSPlayerEvent.Pause, PlayerEventSource.UI) @@ -714,6 +720,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( // this is the standard, expected suppression for this obtainStyledAttributes pattern. @SuppressLint("ResourceType") private fun showCompressorDialog() { + onPlayerInteraction() val act = activity ?: return val compressor = (player as? CS3IPlayer)?.compressor ?: return @@ -1098,7 +1105,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( * (tap, swipe or key press). Lets subclasses abort automatic actions * such as the auto-skip countdown. */ - protected open fun onPlayerInteraction() {} + override fun onPlayerInteraction() {} override fun onSingleTap() { onPlayerInteraction() @@ -1505,64 +1512,77 @@ open class FullScreenPlayer : AbstractPlayerFragment( } playerRotateBtt.setOnClickListener { + onPlayerInteraction() autoHide() toggleRotate() } // init clicks playerResizeBtt.setOnClickListener { + onPlayerInteraction() autoHide() nextResize() } playerSpeedBtt.setOnClickListener { + onPlayerInteraction() autoHide() showSpeedDialog() } playerCompressorBtt.setOnClickListener { + onPlayerInteraction() autoHide() showCompressorDialog() } playerSkipOp.setOnClickListener { + onPlayerInteraction() autoHide() skipOp() } playerSkipEpisode.setOnClickListener { + onPlayerInteraction() autoHide() player.handleEvent(CSPlayerEvent.NextEpisode) } playerGoForward.setOnClickListener { + onPlayerInteraction() autoHide() player.handleEvent(CSPlayerEvent.NextEpisode) } playerRestart.setOnClickListener { + onPlayerInteraction() autoHide() player.handleEvent(CSPlayerEvent.Restart) } playerLock.setOnClickListener { + onPlayerInteraction() autoHide() toggleLock() } playerSubtitleOffsetBtt.setOnClickListener { + onPlayerInteraction() showSubtitleOffsetDialog() } playerGoBack.setOnClickListener { + onPlayerInteraction() activity?.popCurrentPage("FullScreenPlayer") } playerSourcesBtt.setOnClickListener { + onPlayerInteraction() showMirrorsDialogue() } playerTracksBtt.setOnClickListener { + onPlayerInteraction() showTracksDialogue() } @@ -1576,6 +1596,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( @SuppressLint("ClickableViewAccessibility") exoProgress.setOnTouchListener { _, event -> + onPlayerInteraction() // this makes the bar not disappear when sliding when (event.action) { MotionEvent.ACTION_DOWN, @@ -1590,6 +1611,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( return@setOnTouchListener false } playerEpisodesButton.setOnClickListener { + onPlayerInteraction() toggleEpisodesOverlay(show = true) } } @@ -1634,6 +1656,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( } private fun toggleEpisodesOverlay(show: Boolean) { + if (show) onPlayerInteraction() if (show && !isShowingEpisodeOverlay) { previousPlayStatus = player.getIsPlaying() player.handleEvent(CSPlayerEvent.Pause) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 8d1491a8427..f091de78f36 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -241,10 +241,12 @@ class GeneratorPlayer : FullScreenPlayer() { super.playerStatusChanged() if (player.getIsPlaying()) { viewModel.forceClearCache = false - } else if (currentPlayerStatus == CSPlayerLoading.IsPaused) { - // Never seek away while the user has paused the video + } else { + // Never seek away while the user has paused or stopped the video + if (autoSkipJob?.isActive == true) { + declinedTimestamp = shownTimestamp + } cancelAutoSkipCountdown() - declinedTimestamp = shownTimestamp } } @@ -598,6 +600,7 @@ class GeneratorPlayer : FullScreenPlayer() { override fun openOnlineSubPicker( context: Context, loadResponse: LoadResponse?, dismissCallback: (() -> Unit) ) { + onPlayerInteraction() val providers = subsProviders.toList() val isSingleProvider = subsProviders.size == 1 @@ -1020,6 +1023,7 @@ class GeneratorPlayer : FullScreenPlayer() { override fun showMirrorsDialogue() { + onPlayerInteraction() try { currentSelectedSubtitles = player.getCurrentPreferredSubtitle() //println("CURRENT SELECTED :$currentSelectedSubtitles of $currentSubs") @@ -1415,6 +1419,7 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun showTracksDialogue() { + onPlayerInteraction() try { //println("CURRENT SELECTED :$currentSelectedSubtitles of $currentSubs") context?.let { ctx -> @@ -1729,7 +1734,27 @@ class GeneratorPlayer : FullScreenPlayer() { var maxEpisodeSet: Int? = null var hasRequestedStamps: Boolean = false + private var lastRecordedPosition: Long = 0L + override fun playerPositionChanged(position: Long, duration: Long) { + if (position < lastRecordedPosition - 1000L) { + // User sought backwards: allow auto-skip to trigger again + declinedTimestamp = null + shownTimestamp = null + } else { + declinedTimestamp?.let { declined -> + if (position >= declined.timestamp.endMs || position < declined.timestamp.startMs) { + declinedTimestamp = null + } + } + shownTimestamp?.let { shown -> + if (position >= shown.timestamp.endMs || position < shown.timestamp.startMs) { + shownTimestamp = null + } + } + } + lastRecordedPosition = position + // Don't save livestream data if ((currentMeta as? ResultEpisode)?.tvType?.isLiveStream() == true) return @@ -2107,6 +2132,35 @@ class GeneratorPlayer : FullScreenPlayer() { autoSkipJob = null } + private var hideSkipButtonRunnable: Runnable? = null + + private fun scheduleHideSkipButton(delayMs: Long) { + cancelHideSkipButton() + val runnable = Runnable { + displayTimeStamp(false) + } + hideSkipButtonRunnable = runnable + playerBinding?.skipChapterButton?.postDelayed(runnable, delayMs) + } + + private fun cancelHideSkipButton() { + hideSkipButtonRunnable?.let { + playerBinding?.skipChapterButton?.removeCallbacks(it) + } + hideSkipButtonRunnable = null + } + + private fun performSkip(timestamp: VideoSkipStamp) { + cancelHideSkipButton() + cancelAutoSkipCountdown() + player.handleEvent(CSPlayerEvent.SkipCurrentChapter) + val currentPos = player.getPosition() ?: 0L + if (currentPos < timestamp.timestamp.endMs && !timestamp.skipToNextEpisode) { + player.seekTo(timestamp.timestamp.endMs + 500L) + } + onTimestampSkipped(timestamp) + } + /** * Counts down on the skip button and skips the chapter once it reaches * zero. The countdown is cancelled by any user interaction (see @@ -2117,12 +2171,13 @@ class GeneratorPlayer : FullScreenPlayer() { cancelAutoSkipCountdown() if (!isAutoSkipEnabled(timestamp)) return if (timestamp == declinedTimestamp) return + if (currentPlayerStatus == CSPlayerLoading.IsPaused) return declinedTimestamp = null val countdownSeconds = getAutoSkipCountdownSeconds() if (countdownSeconds <= 0) { // Skip instantly when the countdown is set to zero - player.handleEvent(CSPlayerEvent.SkipCurrentChapter) + performSkip(timestamp) return } @@ -2130,6 +2185,12 @@ class GeneratorPlayer : FullScreenPlayer() { try { for (secondsRemaining in countdownSeconds downTo 1) { if (skipIndex != currentIndex) return@launch + if (currentPlayerStatus == CSPlayerLoading.IsPaused) { + cancelAutoSkipCountdown() + declinedTimestamp = shownTimestamp + scheduleHideSkipButton(4000L) + return@launch + } playerBinding?.skipChapterButton?.setText( txt( @@ -2141,13 +2202,13 @@ class GeneratorPlayer : FullScreenPlayer() { delay(1000) } - if (skipIndex == currentIndex) { - player.handleEvent(CSPlayerEvent.SkipCurrentChapter) + if (skipIndex == currentIndex && currentPlayerStatus != CSPlayerLoading.IsPaused) { + performSkip(timestamp) } } finally { // Restore the plain label no matter how the countdown ended // (fired, cancelled or replaced by a new timestamp) - if (skipIndex == currentIndex) { + if (skipIndex == currentIndex && timestampShowState) { playerBinding?.skipChapterButton?.setText(timestamp.uiText) } } @@ -2155,10 +2216,13 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onPlayerInteraction() { - // The user wants manual control: stop the countdown and never - // auto-skip the currently shown timestamp again - cancelAutoSkipCountdown() - declinedTimestamp = shownTimestamp + // The user wants manual control: stop the countdown and decline + // the currently shown timestamp if the countdown was active + if (autoSkipJob?.isActive == true) { + declinedTimestamp = shownTimestamp + cancelAutoSkipCountdown() + scheduleHideSkipButton(4000L) + } } private fun displayTimeStamp(show: Boolean) { @@ -2212,8 +2276,11 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun onTimestampSkipped(timestamp: VideoSkipStamp) { + cancelHideSkipButton() cancelAutoSkipCountdown() displayTimeStamp(false) + shownTimestamp = null + declinedTimestamp = null } /** Timestamp currently shown on the skip button */ @@ -2226,17 +2293,24 @@ class GeneratorPlayer : FullScreenPlayer() { // already showing it, otherwise the countdown restarts endlessly if (timestamp == shownTimestamp && timestampShowState) return + cancelHideSkipButton() shownTimestamp = timestamp playerBinding?.skipChapterButton?.setText(timestamp.uiText) displayTimeStamp(true) val currentIndex = skipIndex - playerBinding?.skipChapterButton?.handler?.postDelayed({ - if (skipIndex == currentIndex) - displayTimeStamp(false) - }, 6000) - startAutoSkipCountdown(timestamp, currentIndex) + + val isAutoSkip = isAutoSkipEnabled(timestamp) && timestamp != declinedTimestamp + if (isAutoSkip) { + // Countdown will handle skipping and hiding when done + startAutoSkipCountdown(timestamp, currentIndex) + } else { + // Auto-skip is not active for this stamp: hide the manual skip button after 6s + scheduleHideSkipButton(6000L) + } } else { + cancelHideSkipButton() shownTimestamp = null + declinedTimestamp = null cancelAutoSkipCountdown() displayTimeStamp(false) } @@ -2249,6 +2323,7 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun showEpisodesOverlay() { + onPlayerInteraction() try { playerBinding?.apply { playerEpisodeList.setRecycledViewPool(EpisodeAdapter.sharedPool) @@ -2322,6 +2397,11 @@ class GeneratorPlayer : FullScreenPlayer() { @MainThread fun releasePlayer() { + cancelHideSkipButton() + cancelAutoSkipCountdown() + shownTimestamp = null + declinedTimestamp = null + lastRecordedPosition = 0L player.release() currentSelectedSubtitles = null currentSelectedLink = null diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt index c363a29b3aa..eb77db1a182 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt @@ -134,6 +134,8 @@ class PlayerView @JvmOverloads constructor( fun playerUpdated(player: Any?) {} /** Called on a short single-tap on empty player area (no swipe, no double-tap). */ fun onSingleTap() {} + /** Called whenever the user interacts with the player controls (tap, button click, etc.). */ + fun onPlayerInteraction() {} /** Called when the hold-for-speedup gesture starts (show=true) or ends (show=false). */ fun onHoldSpeedUp(show: Boolean) {} /** Called during brightness swipe with the current extra-brightness alpha (0–1). */ @@ -378,6 +380,7 @@ class PlayerView @JvmOverloads constructor( exoFfwdText?.text = context.getString(R.string.ffw_text_regular_format).format(seekSecs) playerPausePlay?.setOnClickListener { + callbacks?.onPlayerInteraction() scheduleAutoHide() if (currentPlayerStatus == CSPlayerLoading.IsEnded && isLayout(PHONE)) { player.handleEvent(CSPlayerEvent.Restart, PlayerEventSource.UI) @@ -386,10 +389,12 @@ class PlayerView @JvmOverloads constructor( } } playerRew?.setOnClickListener { + callbacks?.onPlayerInteraction() scheduleAutoHide() gestureHelper.rewind() } playerFfwd?.setOnClickListener { + callbacks?.onPlayerInteraction() scheduleAutoHide() gestureHelper.fastForward() } @@ -817,7 +822,9 @@ class PlayerView @JvmOverloads constructor( player.handleEvent(CSPlayerEvent.NextEpisode, source = PlayerEventSource.Player) } } - is PauseEvent -> Unit + is PauseEvent -> { + callbacks?.onPlayerInteraction() + } is PlayEvent -> Unit } }