@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
Markdown
# š„ @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