Web · Components
VideoPlayer
Video player matching the library's design.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Reels style: muted, looping, pauses on tap
Import
Video player matching the library's design. Uses the browser's native <video> element (hardware decoding, battery friendly); only the controls are ours and look the same in every browser.
- Controls: Play/pause, a position bar showing the buffer (time bubble on hover), volume, duration, subtitle, speed and quality menu, picture-in-picture, full screen. While playing they hide when the mouse stops; in full screen the cursor hides too.
- Keyboard: Space/K play-pause, ←/→
seekStepseconds, J/L twice that, ↑/↓ volume, M mute, F full screen, C subtitles, 0–9 percent of the video,</>speed, Home/End start/end. - Mobile: Tapping shows the controls; double tapping right or left seeks forward/back (like YouTube). Entering full screen locks a landscape video to landscape. On iPhone full screen opens with the system player.
- Full screen: The player itself goes full screen; controls, title and menus work the same.
- Quality: Sources in the
srcarray with alabelbecome the quality menu; the position is kept on switch. - The volume is remembered; the title and cover show on the lock screen (Media Session).
Videos in the gallery open with this player in the full screen view (see Gallery).
Client component.
Examples
Shows the first frame of a video without a cover image as an image (covers the box, absolute inset-0). Empty until the frame is extracted; if it can't be converted to an image, the video is shown paused on the first frame.
Examples
cachedVideoFrame
functionThe extracted frame if cached; otherwise undefined.
extractVideoFrame
functionExtracts the first frame of a video (see the top of the file). A single job runs per URL; the result is cached. When signal is aborted and nobody else is waiting, the job leaves the queue or is stopped. null if the video can't be opened.
Examples
useVideoFrame
functionFirst frame of a video without a cover image. No work starts while enabled is false. If target is given (or is still null) work starts only when that element comes on screen (within 200 px); when it leaves the screen the pending work is cancelled.
VideoFrame
interfaceResult of extractVideoFrame.
| Name | Type | Description |
|---|---|---|
url | string | undefined | Image URL of the frame (blob:). undefined if the frame couldn't be converted to an image (CORS); then the video should be shown paused on the first frame. |
width | number | Intrinsic width of the video (px). |
height | number | Intrinsic height of the video (px). |
VideoFrameImageProps
interfaceProps of VideoFrameImage.
Extends: Omit<ComponentProps<"span">, "children">
| Name | Type | Default | Description |
|---|---|---|---|
src | string | Video address. | |
fit? | "cover" | "contain" | "cover" | object-fit. |
onFrame? | (frame: VideoFrame) => void | When the frame is extracted (to measure the aspect ratio). |
VideoSource
interfaceA video source for VideoPlayer.
| Name | Type | Description |
|---|---|---|
src | string | Video address. |
type? | string | MIME type (video/webm); the browser picks the first source it can play. |
label? | string | Quality name ("1080p", "720p"). If one of the sources has a name, a quality menu appears in settings; position and playback state are kept on switch. The first source is the default. |
VideoTrack
interfaceSubtitle file (WebVTT) for VideoPlayer.
| Name | Type | Default | Description |
|---|---|---|---|
src | string | URL of the .vtt file. | |
srcLang | string | Language code ("tr", "en"). | |
label | string | Name shown in the menu ("English"). | |
kind? | "subtitles" | "captions" | "subtitles" | Kind. |
default? | boolean | On at start. |
VideoPlayerProps
interfaceProps of the VideoPlayer component.
Extends: Omit<ComponentProps<"div">, "children" | "onPlay" | "onPause" | "onEnded" | "onError" | "onTimeUpdate">
| Name | Type | Default | Description |
|---|---|---|---|
src | string | readonly VideoSource[] | Video URL or source list. See VideoSource. | |
poster? | string | Cover image shown before the video starts. | |
autoPoster? | boolean | true | If poster is omitted, the first frame of the video is extracted in the browser and used as the cover (only the start of the video is downloaded; the result is cached). See extractVideoFrame. |
title? | string | Title. Shown at the top in full screen; used by the player on the lock screen and in the notification area (Media Session). | |
tracks? | readonly VideoTrack[] | Subtitles. See VideoTrack. | |
autoPlay? | boolean | Plays by itself when visible. Browsers may block autoplay with sound; if blocked, the video is muted and played. | |
muted? | boolean | Starts muted. | |
loop? | boolean | Starts over when it ends. | |
preload? | "none" | "metadata" | "auto" | "metadata" | How much is downloaded when the page opens. "metadata" only the duration and first frame, "auto" enough to be ready to play. |
controls? | boolean | "minimal" | true | Controls: true the full bar; "minimal" Reels/Shorts style (tap to pause/play, a thin progress bar and mute button at the bottom); false none. |
aspectRatio? | number | "auto" | "fill" | 16 / 9 | Aspect ratio. A number (16 / 9), "auto" (the video's own ratio) or "fill" (fills the container; you give the size). |
fit? | "contain" | "cover" | "contain" | How the picture fits the box. |
playbackRates? | readonly number[] | [0.5, 0.75, 1, 1.25, 1.5, 2] | Speeds in settings. |
seekStep? | number | 5 | Time skipped with arrow keys (seconds). A double tap skips twice that. |
startTime? | number | Start position (seconds). | |
rememberVolume? | boolean | true | Remember the volume in the browser; all players on the same site open with the last chosen volume. |
label? | string | title | Screen reader name of the player. |
onPlay? | () => void | When playback starts. | |
onPause? | () => void | On pause. | |
onEnded? | () => void | On end. | |
onTimeUpdate? | (time: number, duration: number) => void | When the position changes (a few times per second), with the current position and duration. | |
onError? | () => void | When the video can't be opened. | |
videoRef? | Ref<HTMLVideoElement> | The underlying <video> element; to control playback from code. |