Skip to content
video-player-example.tsx
A video with its own controls over the picture, and a compact variant for cards and feeds.
Installation#
bunx --bun fabricator-ui@latest add video-player
Usage#
import { Text } from "@/components/ui/text"
import { VideoPlayer } from "@/components/ui/video-player"<VideoPlayer
src="https://fabricator-ui.vercel.app/media/sintel-trailer.mp4"
poster="https://fabricator-ui.vercel.app/media/sintel-trailer.jpg"
title="Sintel, trailer"
chapters={[
{ start: 0, title: "The mountains" },
{ start: 10, title: "The gatekeeper" },
{ start: 24, title: "The dragon" },
{ start: 35, title: "The quest" },
{ start: 46, title: "Credits" },
]}
tracks={[
{
src: "https://fabricator-ui.vercel.app/media/sintel-trailer.en.vtt",
srcLang: "en",
label: "English",
},
{
src: "https://fabricator-ui.vercel.app/media/sintel-trailer.pt.vtt",
srcLang: "pt-BR",
label: "Português",
},
]}
onPlayingChange={setIsPlaying}
className="w-full"
/>
<Text className="text-(length:--density-text-12) text-muted-foreground">
{isPlaying ? "Playing" : "Paused"} · Sintel © Blender Foundation, CC
BY 3.0
</Text>Composition#
VideoPlayerVideoPlayerChapterVideoPlayerPropsVideoPlayerTrackVideoPlayerVariant
Examples#
import * as React from "react"
import { Text } from "@/components/ui/text"
import { VideoPlayer } from "@/components/ui/video-player"
const MEDIA = "https://fabricator-ui.vercel.app/media"
const TRACKS = [
{
src: `${MEDIA}/sintel-trailer.en.vtt`,
srcLang: "en",
label: "English",
},
{
src: `${MEDIA}/sintel-trailer.pt.vtt`,
srcLang: "pt-BR",
label: "Português",
},
]
function VideoPlayerExample() {
const [isPlaying, setIsPlaying] = React.useState(false)
return (
<ExampleWrapper fit>
<Example title="Default, with chapters and captions">
<VideoPlayer
src="https://fabricator-ui.vercel.app/media/sintel-trailer.mp4"
poster="https://fabricator-ui.vercel.app/media/sintel-trailer.jpg"
title="Sintel, trailer"
chapters={[
{ start: 0, title: "The mountains" },
{ start: 10, title: "The gatekeeper" },
{ start: 24, title: "The dragon" },
{ start: 35, title: "The quest" },
{ start: 46, title: "Credits" },
]}
tracks={[
{
src: "https://fabricator-ui.vercel.app/media/sintel-trailer.en.vtt",
srcLang: "en",
label: "English",
},
{
src: "https://fabricator-ui.vercel.app/media/sintel-trailer.pt.vtt",
srcLang: "pt-BR",
label: "Português",
},
]}
onPlayingChange={setIsPlaying}
className="w-full"
/>
<Text className="text-(length:--density-text-12) text-muted-foreground">
{isPlaying ? "Playing" : "Paused"} · Sintel © Blender Foundation, CC
BY 3.0
</Text>
</Example>
<Example title="Captions on from the start">
<VideoPlayer
src={`${MEDIA}/sintel-trailer.mp4`}
poster={`${MEDIA}/sintel-trailer.jpg`}
title="Sintel, trailer"
tracks={[{ ...TRACKS[0], default: true }, TRACKS[1]]}
playbackRates={[0.5, 1, 1.5, 2]}
className="w-full"
/>
</Example>
<Example title="Compact">
<VideoPlayer
variant="compact"
src={`${MEDIA}/sintel-trailer.mp4`}
poster={`${MEDIA}/sintel-trailer.jpg`}
title="Sintel, trailer"
className="w-full"
/>
</Example>
<Example title="Autoplay, muted and looping">
<VideoPlayer
variant="compact"
src={`${MEDIA}/sintel-trailer.mp4`}
title="Sintel, trailer"
autoPlay
muted
loop
className="w-full"
/>
</Example>
<Example title="A video that can't load">
<VideoPlayer
src={`${MEDIA}/missing-video.mp4`}
title="A video that can't load"
className="w-full"
/>
</Example>
</ExampleWrapper>
)
}
export { VideoPlayerExample }Differences from web#
New engine. expo-video plays the video in place of the browser's <video>. A tap shows or hides the controls and a double tap plays or pauses. Captions are read from the same WebVTT files and drawn by the player. Settings open as a bottom sheet in the theme's colours, full screen is the system's player with its own controls, and there's no volume slider: the device's buttons set the volume. There are no keyboard shortcuts.
Accessibility#
Parts set role="alert", role="button", role="menu", role="radio", role="separator", read by VoiceOver and TalkBack. Give a control with no text an accessibilityLabel.