UNPKG

@streamspark/react-video-player

Version:

A fully-featured, YouTube-like video player built completely from scratch using React and TypeScript.

205 lines (147 loc) • 6.7 kB
# šŸŽ„ @streamspark/react-video-player A fully-featured, YouTube-like video player built completely from scratch using **React** and **TypeScript** — no third-party video libraries involved. Perfect for developers looking for a **clean**, **minimal**, **extensible**, and **dependency-free** media player. --- ## āœ… Features - šŸŽ¬ Custom Play/Pause/Seek Controls (with buffering indicator) - šŸ”Š Volume Control (with mute toggle) - ā© Enhanced Seek Bar (with time and buffer display) - āš™ļø Playback Speed Adjustment (0.25x to 2x) - 🌐 Subtitles Support (.vtt WebVTT format) - šŸ“ŗ Fullscreen Toggle - šŸŒ“ Light & Dark Themes - šŸ“± Responsive Layout (mobile-friendly) - šŸŽ® YouTube-like Keyboard Shortcuts - šŸŽÆ TypeScript Support (fully typed with IntelliSense) - ♿ Accessibility (ARIA + Screen Reader support) - šŸŽØ Easy Styling via CSS Variables - šŸ“¦ Zero Dependencies (only React + Lucide icons) --- ## šŸš€ Live Demo Try it online (no setup required): šŸ‘‰ [StackBlitz Demo](https://stackblitz.com/github/arun59ay/react-video-player) --- šŸ”— Links šŸ”§ [GitHub](https://github.com/arun59ay/react-video-player): https://github.com/arun59ay/react-video-player šŸ“¦ [NPM](https://www.npmjs.com/package/@streamspark/react-video-player): https://www.npmjs.com/package/@streamspark/react-video-player ⚔ [Live Demo](https://stackblitz.com/github/arun59ay/react-video-player): https://stackblitz.com/github/arun59ay/react-video-player ## šŸ“¦ Installation ```bash npm install @streamspark/react-video-player You also need to import the default styles manually: import '@streamspark/react-video-player/dist/index.css'; import React from 'react'; import { VideoPlayer } from '@streamspark/react-video-player'; import '@streamspark/react-video-player/dist/index.css'; export default function App() { return ( <VideoPlayer src="/videos/sample.mp4" poster="/images/thumb.jpg" title="Demo Player" theme="dark" /> ); } import React from 'react'; import { VideoPlayer } from '@streamspark/react-video-player'; import '@streamspark/react-video-player/dist/index.css'; const App = () => ( <VideoPlayer src="/videos/sample.mp4" poster="/images/thumb.jpg" captions="/captions/subtitles.vtt" title="Advanced Demo Player" theme="light" autoplay={false} loop={false} muted={false} controls={true} width="800px" height="450px" className="my-custom-player" style={{ borderRadius: '12px' }} onPlay={() => console.log('Video started')} onPause={() => console.log('Video paused')} onTimeUpdate={(time) => console.log('Time:', time)} onVolumeChange={(vol) => console.log('Volume:', vol)} onSeek={(time) => console.log('Seeked to:', time)} onEnded={() => console.log('Ended')} onError={(err) => console.error('Error:', err)} /> ); šŸŽ® Keyboard Shortcuts | Action | Keys | | ----------------- | --------- | | Play / Pause | Space / K | | Seek -10s | ← / J | | Seek +10s | → / L | | Volume Up | ↑ | | Volume Down | ↓ | | Mute / Unmute | M | | Fullscreen Toggle | F | | Speed Down | Shift + , | | Speed Up | Shift + . | | Go to Start | Home | | Go to End | End | šŸ“‹ Props API | Prop | Type | Default | Description | | ----------- | --------------------- | ----------- | ----------------------------------- | | `src` | `string` | — *(req)* | Video source URL | | `poster` | `string` | `undefined` | Poster image | | `captions` | `string` | `undefined` | WebVTT subtitles file | | `title` | `string` | `undefined` | Accessible title for screen readers | | `theme` | `'light' \| 'dark'` | `'dark'` | UI Theme | | `autoplay` | `boolean` | `false` | Autoplay on load | | `loop` | `boolean` | `false` | Loop the video | | `muted` | `boolean` | `false` | Mute by default | | `controls` | `boolean` | `true` | Show/hide player controls | | `width` | `string` or `number` | `'100%'` | Custom player width | | `height` | `string` or `number` | `'auto'` | Custom player height | | `className` | `string` | `''` | Custom class for the wrapper | | `style` | `React.CSSProperties` | `{}` | Inline styles | 🧠 Event Callbacks | Callback | Type | Description | | ---------------- | -------------------------- | ------------------------------ | | `onPlay` | `() => void` | Triggered when playback starts | | `onPause` | `() => void` | Triggered when paused | | `onTimeUpdate` | `(time: number) => void` | On time change during playback | | `onVolumeChange` | `(volume: number) => void` | On volume update | | `onSeek` | `(time: number) => void` | When seeking is done | | `onEnded` | `() => void` | When video ends | | `onError` | `(error: string) => void` | If video load/playback fails | 🧩 Project Structure @streamspark/react-video-player/ ā”œā”€ā”€ src/ │ ā”œā”€ā”€ components/ # All modular player components │ ā”œā”€ā”€ hooks/ # Custom video hook │ ā”œā”€ā”€ types/ # Type definitions │ ā”œā”€ā”€ styles/ # CSS styles │ └── index.ts # Entry point ā”œā”€ā”€ demo/ # Vite + manual CSS demo project ā”œā”€ā”€ dist/ # Compiled output ā”œā”€ā”€ package.json ā”œā”€ā”€ tsconfig.json └── README.md šŸŽØ Custom Styling You can override styling using CSS variables: .rvp-video-player { --rvp-primary-color: #ff0000; --rvp-background-color: rgba(0, 0, 0, 0.8); --rvp-text-color: white; --rvp-border-radius: 8px; } 🚫 Built Without āŒ react-player āŒ hls.js āŒ video.js āŒ External state libraries āŒ UI frameworks All features built from scratch using native DOM APIs + React + Tailwind. šŸ¤ Contributing Found a bug or want to add a feature? We welcome contributions — PRs and issues are appreciated! šŸ“„ License MIT License — See LICENSE for details. --- Made with ā¤ļø by Arun YT