Overview
TheVideoPlayer component is a fully-featured HTML5 video player that replicates YouTube’s player experience. It includes playback controls, quality settings, subtitles, chapters, keyboard shortcuts, and multiple viewing modes (theater, fullscreen, mini-player).
Props
The video object containing all metadata and URLs. See Video type for details.
Whether to automatically start playing the video when it loads.
Callback function called when the video finishes playing (unless looping is enabled).
Callback function for the “Next” button. If not provided, the Next button is hidden.
Callback function for the “Previous” button. If not provided, the Previous button is hidden.
Features
Playback Controls
- Play/Pause with visual feedback
- Progress bar with chapter markers
- Volume control with mute toggle
- Playback speed control (0.25x to 2x)
- Next/Previous navigation
- Loop/repeat mode
Viewing Modes
- Normal: Standard player with rounded corners
- Theater Mode: Full-width player without rounded corners
- Fullscreen: Native browser fullscreen
- Mini Player: Picture-in-picture style floating player
Advanced Features
- Chapters: Visual markers on progress bar with hover tooltips
- Subtitles: Toggle subtitles on/off
- Quality Selection: Switch between available video qualities
- Audio Tracks: Select different audio tracks
- Nerd Stats: Display technical information (resolution, bitrate, codec, fps, buffer health)
- Buffering: Visual buffer progress indicator
Keyboard Shortcuts
The player supports YouTube-style keyboard shortcuts:| Key | Action |
|---|---|
Space or K | Play/Pause |
J | Skip backward 10 seconds |
L | Skip forward 10 seconds |
← | Skip backward 5 seconds |
→ | Skip forward 5 seconds |
↑ | Increase volume |
↓ | Decrease volume |
M | Toggle mute |
F | Toggle fullscreen |
T | Toggle theater mode |
I | Toggle mini player |
C | Toggle subtitles |
0-9 | Seek to 0%, 10%, 20%, …, 90% of the video |
Touch Gestures
- Double tap: Skip forward/backward (left/right side of screen)
- Horizontal swipe: Seek through the video
- Auto-hide controls: Controls fade after 3 seconds of inactivity during playback
Usage Example
YouTube Embed Support
The component automatically detects YouTube embed URLs and renders an iframe instead of the HTML5 video element:Integration with Other Components
With VideoInfo Component
CombineVideoPlayer with VideoInfo to create a complete video viewing experience:
Source Code Reference
The VideoPlayer component is located at:/workspace/source/src/components/youtube/VideoPlayer.tsx:47-955
- Uses React refs for video element and container
- Implements custom progress bar with chapter markers
- Handles fullscreen API for cross-browser compatibility
- Manages playback state with React hooks
- Supports both controlled and uncontrolled playback modes