Skip to content

feat: add spacebar hold for 2x speed in player with proper listener c…#1923

Open
i-amansharma07 wants to merge 1 commit into
code100x:mainfrom
i-amansharma07:player-spacebar-hold
Open

feat: add spacebar hold for 2x speed in player with proper listener c…#1923
i-amansharma07 wants to merge 1 commit into
code100x:mainfrom
i-amansharma07:player-spacebar-hold

Conversation

@i-amansharma07
Copy link
Copy Markdown

What was missing

The player had no way to temporarily boost speed by holding a key. This PR adds the spacebar hold gesture which is a common pattern in video players (e.g. YouTube).

What was added

  • Holding space kicks the playback rate to 2x
  • Releasing space restores the previous playback rate (not hardcoded to 1x — respects whatever rate the user was already at)
  • If the video was paused when the hold started, it auto-plays during the hold
  • A quick tap of space still toggles play/pause as expected
Action Result
Hold space Playback jumps to 2x
Release space Restores previous rate
Tap space while playing Pauses
Tap space while paused Plays
Hold space while paused Auto-plays at 2x, restores on release

Cleanup Logic

Both listeners are correctly registered and removed:

keydown is registered with { capture: true } so it fires before Video.js
internal handlers can intercept it. The removal must mirror the same flag —
without it, the browser treats capture and non-capture registrations as distinct
listeners and the removal becomes a no-op, leaking the listener on every unmount.

keyup removal was simply absent, causing a new duplicate listener to stack up
on every re-render triggered by player state changes.

Checklist before requesting a review

  • [✅] I have performed a self-review of my code
  • [✅] I assure there is no similar/duplicate pull request regarding same issue

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.

1 participant