Skip to content

feat(player): add autoplay next episode with countdown overlay#57

Merged
truelockmc merged 3 commits into
truelockmc:mainfrom
rogueburger21:feature/autoplay-countdown
Jun 5, 2026
Merged

feat(player): add autoplay next episode with countdown overlay#57
truelockmc merged 3 commits into
truelockmc:mainfrom
rogueburger21:feature/autoplay-countdown

Conversation

@rogueburger21
Copy link
Copy Markdown
Contributor

@rogueburger21 rogueburger21 commented May 16, 2026

Addresses #16

Description

This PR implements an autoplay feature for TV series. When an episode finishes, a countdown overlay appears, allowing the user to seamlessly transition to the next episode or cancel autoplay.

Changes

  • Autoplay Lifecycle: Introduced autoplayCountdown state and refs to track when the video has ended.
  • Countdown Trigger: Automatically initiates a 5-second countdown when the video has 1 second or less remaining.
  • Overlay UI: Added a blurred overlay over the player with the next episode's title and a countdown timer. Includes "Cancel" and "Play Now" actions.
  • Playback: Ensures playback proceeds automatically to the next available, unrestricted episode.

@rogueburger21 rogueburger21 mentioned this pull request May 16, 2026
11 tasks
- Detect when current episode reaches its final seconds and trigger
  an autoplay countdown via a new useEffect tied to the video
  progress polling loop.
- Render a full-screen overlay showing a circular countdown timer
  (10 → 0) with "Play Now" and "Cancel" controls so users stay in
  charge of the transition.
- Automatically advance to the next episode when the timer expires,
  using the existing playEpisode helper and episode ordering logic.
- Guard against edge cases: unreleased episodes, last-episode-of-
  season boundaries, and rapid re-triggers via a ref-based lock
  (countdownStartedRef).
@rogueburger21 rogueburger21 force-pushed the feature/autoplay-countdown branch from 43267f9 to 329d1bd Compare May 16, 2026 18:15
Copy link
Copy Markdown

@codeCraft-Ritik codeCraft-Ritik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! The implementation looks clean, and the change feels well-scoped.

Copy link
Copy Markdown
Owner

@truelockmc truelockmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, but here are some things I would like to have changed:

  1. Could you wire it up into the Settings tho? In the Playback category. You should be able to dis-/enable it and change how long the timer is before it plays. (Also add the new storage keys to backup.js then) If the timer is set to 0 it should just show the overlay with buttons and not play automatically.
  2. Also please move the newly added auto-play code segments into a new file (src/utils/useAutoplay)
  3. I think it would make sense to use the autoplay next together with the already existing Auto-Watched thing. So that once the amount of time remaining is smaller then that treshold it shows the overlay, instead of hardcoding that to 5s.
const [watchedThreshold] = useState(() => storage.get("watchedThreshold") ?? 20);
  1. Please add a cancel button to cancel the countdown and continue playing the current episode. You described that in your PR, but i do not see it here.
  2. You dont have to do this, but i think it'd be cool if the overlay darkened over the whole player. But the Episode titel and the cover image of that Episode would be shown only in the right or left part of the player (that could also be changed in the settings). Then the "Cancel" and "Play now" button (should be bigger than it is right now) should be shown below that.
  3. Track nextEp in a ref that's always current, and read from that inside the interval instead of the closure.
const nextEpRef = useRef(nextEp);
useEffect(() => { nextEpRef.current = nextEp; }, [nextEp]);

// inside the interval callback:
playEpisode(nextEpRef.current);

Because if nextEp changes while the countdown is active (e.g. season data reloads mid-countdown, or a race condition on episode group fetch), the wrong episode plays. This is unlikely but rather safe than sorry ig.

Please tell me what you think of the design idea (5.) and implement the other things : )

tysm

@truelockmc
Copy link
Copy Markdown
Owner

truelockmc commented Jun 1, 2026

@rogueburger21 Hi, are you still going to work on this PR?

If not, I will merge your current changes into a new branch and implement the requests from my review.

@rogueburger21
Copy link
Copy Markdown
Contributor Author

Hey @truelockmc — yes, still on it! Sorry for the delay. I've worked through all the points from your review and I'm just doing a final pass before pushing.
Quick rundown:

1. Settings wiring — added an "Autoplay Next Episode" section under Playback: enable/disable toggle + configurable countdown duration. New keys
(autoplayNextEnabled, autoplayNextDuration, autoplayNextLayout) are in storage.js and added to backup.js. Duration 0 now just shows the overlay with the
buttons and doesn't auto-play.
2. Refactor — moved all the autoplay logic into src/utils/useAutoplay.js.
3. Threshold — the overlay now triggers off the existing watchedThreshold instead of the hardcoded 5s.
4. Cancel — added a Cancel button that stops the countdown and keeps the current episode playing.
5. Design (your idea 5.) — went with it: the whole player darkens and the next-episode title + cover still show in a side panel, with a setting to put it on
the left or right and bigger Play Now / Cancel buttons below. Let me know if the layout matches what you had in mind.
6. nextEp ref — nextEp is now tracked in a ref and the interval reads from nextEpRef.current, so the right episode plays even if it changes mid-countdown.

Pushing the commit shortly!

rogueburger21 added a commit to rogueburger21/streambert that referenced this pull request Jun 2, 2026
Addresses review feedback on PR truelockmc#57:
- Move autoplay countdown logic into a dedicated src/utils/useAutoplay hook
- Add an "Autoplay Next Episode" section to Settings > Playback: enable/disable
  toggle, configurable countdown duration, and overlay side (left/right). A
  duration of 0 shows the overlay with buttons only and does not auto-advance.
- Persist the new keys (autoplayNextEnabled / autoplayNextDuration /
  autoplayNextLayout) and add them to backup.js
- Trigger the overlay using the existing watchedThreshold instead of a
  hardcoded 5s
- Read nextEp from an always-current ref inside the countdown interval so the
  correct episode plays if season data reloads mid-countdown
- Redesign the overlay: darkened player with a side panel showing the next
  episode's still, title, and larger Cancel / Play Now actions

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@truelockmc
Copy link
Copy Markdown
Owner

Great, tysm.

One thing tho, please make this dropdown shorter.
image

like this:
image

And for the future please do not directly use claude as a contributor.

rogueburger21 added a commit to rogueburger21/streambert that referenced this pull request Jun 3, 2026
Addresses review feedback on PR truelockmc#57:
- Move autoplay countdown logic into a dedicated src/utils/useAutoplay hook
- Add an "Autoplay Next Episode" section to Settings > Playback: enable/disable
  toggle, configurable countdown duration, and overlay side (left/right). A
  duration of 0 shows the overlay with buttons only and does not auto-advance.
- Persist the new keys (autoplayNextEnabled / autoplayNextDuration /
  autoplayNextLayout) and add them to backup.js
- Trigger the overlay using the existing watchedThreshold instead of a
  hardcoded 5s
- Read nextEp from an always-current ref inside the countdown interval so the
  correct episode plays if season data reloads mid-countdown
- Redesign the overlay: darkened player with a side panel showing the next
  episode's still, title, and larger Cancel / Play Now actions
@rogueburger21 rogueburger21 force-pushed the feature/autoplay-countdown branch from 2516f2c to 6f3e254 Compare June 3, 2026 12:14
Addresses review feedback on PR truelockmc#57:
- Move autoplay countdown logic into a dedicated src/utils/useAutoplay hook
- Add an "Autoplay Next Episode" section to Settings > Playback: enable/disable
  toggle, configurable countdown duration, and overlay side (left/right). A
  duration of 0 shows the overlay with buttons only and does not auto-advance.
- Persist the new keys (autoplayNextEnabled / autoplayNextDuration /
  autoplayNextLayout) and add them to backup.js
- Trigger the overlay using the existing watchedThreshold instead of a
  hardcoded 5s
- Read nextEp from an always-current ref inside the countdown interval so the
  correct episode plays if season data reloads mid-countdown
- Redesign the overlay: darkened player with a side panel showing the next
  episode's still, title, and larger Cancel / Play Now actions
@rogueburger21 rogueburger21 force-pushed the feature/autoplay-countdown branch from 6f3e254 to 6c7a228 Compare June 3, 2026 12:19
@rogueburger21
Copy link
Copy Markdown
Contributor Author

Done

@truelockmc
Copy link
Copy Markdown
Owner

Thanks : )

@truelockmc truelockmc merged commit 3b58ddf into truelockmc:main Jun 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants