Video Player
8starlabs-ui/video-playerFreeComponent
A video player component
Install it
npx shadcn@latest add https://ui.8starlabs.com/r/video-player.jsonSource
1"use client";23import React, {4 createContext,5 useContext,6 useEffect,7 useRef,8 useState,9 useCallback10} from "react";11import {12 ChevronDown,13 ChevronUp,14 AlertCircle,15 Maximize2,16 Minimize2,17 Loader2,18 Pause,19 PictureInPicture2,20 Play,21 RotateCcw,22 RotateCw,23 Volume,24 Volume1,25 Volume2,26 VolumeOff27} from "lucide-react";28import { cva, type VariantProps } from "class-variance-authority";29import { cn } from "@/lib/utils";30import { Button } from "@/registry/8starlabs-ui/blocks/button";3132interface VideoContextType {33 videoRef: React.RefObject<HTMLVideoElement | null>;34 containerRef: React.RefObject<HTMLDivElement | null>;35 isPlaying: boolean;36 isBuffering: boolean;37 hasError: boolean;38 videoProgress: number;39 videoDuration: number;40 areControlsShown: boolean;41 isFullscreen: boolean;42 isPip: boolean;43 isVolumeControlOpen: boolean;44 repeatVideoAutomatically: boolean;45 autoPlayVideoUponVisible: boolean;46 autoHideControls: boolean;47 showCenterControls: boolean;48 attemptTogglePlay: () => void;49 toggleFullscreen: () => void;50 setIsPlaying: (playing: boolean) => void;51 setIsBuffering: (buffering: boolean) => void;52 setHasError: (hasError: boolean) => void;53 setVideoProgress: (progress: number) => void;54 setVideoDuration: (videoDuration: number) => void;55 setShowControls: (show: boolean) => void;56 showControlsTemporarily: () => void;57 setVolume: (x: number) => void;58 setIsMouseOverControls: (x: boolean) => void;59 toggleMute: (x: boolean) => void;60 togglePip: () => void;61 setIsVolumeControlOpen: (x: boolean) => void;62 clearControlsTimeout: () => void;63}6465const VideoContext = createContext<VideoContextType | null>(null);6667// Reads the shared video context and guards against using controls outside VideoRoot.68export function useVideo(): VideoContextType {69 const context = useContext(VideoContext);70 if (!context) {71 throw new Error("useVideo must be used within a VideoRoot");72 }73 return context;74}7576export function VideoProvider({77 repeat,78 auto,79 autoHideControls = true,80 showCenterControls = true,81 children82}: {83 repeat: boolean;84 auto: boolean;85 autoHideControls: boolean;86 showCenterControls?: boolean;87 children: React.ReactNode;88}): React.ReactElement {89 // Shared video element ref and UI state consumed by viewport and control components.90 const videoRef = useRef<HTMLVideoElement>(null);91 const containerRef = useRef<HTMLDivElement>(null);92 const lastVolumeRef = useRef<number | null>(null);93// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from 8starlabs-ui
All 74 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Buttonbutton | 8starlabs-ui | Components | Free | 2 deps | |
| Collapsiblecollapsible | 8starlabs-ui | Components | Free | 1 dep | |
| Dropdown Menudropdown-menu | 8starlabs-ui | Components | Free | 2 deps | |
| Flip clockflip-clock | 8starlabs-ui | Components | Free | no deps | |
| Heatmapheatmap | 8starlabs-ui | Components | Free | no deps | |
| Inputinput | 8starlabs-ui | Components | Free | no deps | |
| JSON Viewerjson-viewer | 8starlabs-ui | Components | Free | 1 dep · 3 files | |
| Labellabel | 8starlabs-ui | Components | Free | no deps |
