Initial commit: modern React video player library
Add all source files for a feature-rich, reusable video player built with React, TypeScript, and Vite. Includes core components, context, hooks, utilities, styles, demo app, and configuration files.
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
|
||||
'Droid Sans', 'Helvetica Neue', sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
background-color: #0f172a;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.app {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.app-header {
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
|
||||
border-bottom: 1px solid #334155;
|
||||
}
|
||||
|
||||
.app-header h1 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.app-header p {
|
||||
font-size: 1.1rem;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.app-main {
|
||||
flex: 1;
|
||||
padding: 2rem;
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.video-section {
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.player-wrapper {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto 2rem;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.no-video {
|
||||
aspect-ratio: 16 / 9;
|
||||
background-color: #1e293b;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #64748b;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.controls-section {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.url-input {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.url-input input {
|
||||
flex: 1;
|
||||
padding: 0.75rem 1rem;
|
||||
background-color: #1e293b;
|
||||
border: 2px solid #334155;
|
||||
border-radius: 8px;
|
||||
color: #e2e8f0;
|
||||
font-size: 1rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.url-input input:focus {
|
||||
outline: none;
|
||||
border-color: #ef4444;
|
||||
background-color: #0f172a;
|
||||
}
|
||||
|
||||
.url-input input:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.url-input button {
|
||||
padding: 0.75rem 2rem;
|
||||
background-color: #334155;
|
||||
border: 2px solid #475569;
|
||||
border-radius: 8px;
|
||||
color: #e2e8f0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.url-input button:hover {
|
||||
background-color: #475569;
|
||||
border-color: #64748b;
|
||||
}
|
||||
|
||||
.url-input button.active {
|
||||
background-color: #ef4444;
|
||||
border-color: #ef4444;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.features-section {
|
||||
margin-top: 4rem;
|
||||
}
|
||||
|
||||
.features-section h2 {
|
||||
font-size: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
text-align: center;
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.features-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.feature {
|
||||
background-color: #1e293b;
|
||||
padding: 1.5rem;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #334155;
|
||||
}
|
||||
|
||||
.feature h3 {
|
||||
font-size: 1.3rem;
|
||||
margin-bottom: 1rem;
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
.feature ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.feature li {
|
||||
padding: 0.5rem 0;
|
||||
color: #cbd5e1;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
kbd {
|
||||
display: inline-block;
|
||||
padding: 2px 6px;
|
||||
background-color: #334155;
|
||||
border: 1px solid #475569;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
font-family: monospace;
|
||||
color: #f1f5f9;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.app-footer {
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
background-color: #0f172a;
|
||||
border-top: 1px solid #334155;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.app-footer p {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.app-header h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.app-main {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.url-input {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.features-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import React, { useState } from 'react'
|
||||
import { VideoPlayer } from '../src/components/VideoPlayer'
|
||||
import type { SubtitleTrack } from '../src/types'
|
||||
import './App.css'
|
||||
|
||||
function App() {
|
||||
const [videoUrl, setVideoUrl] = useState('')
|
||||
const [useDemo, setUseDemo] = useState(true)
|
||||
|
||||
// Demo video URLs (you can replace with your own)
|
||||
const demoVideoUrl = '/Stormy Weather_98515ce9/master.m3u8'
|
||||
const demoPoster = undefined
|
||||
|
||||
const demoSubtitles: SubtitleTrack[] = [
|
||||
// Add your subtitle URLs here
|
||||
]
|
||||
|
||||
const currentVideoUrl = useDemo ? demoVideoUrl : videoUrl
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<header className="app-header">
|
||||
<h1>🎬 Modern Video Player</h1>
|
||||
<p>A feature-rich, modern video player built with React</p>
|
||||
</header>
|
||||
|
||||
<main className="app-main">
|
||||
<div className="video-section">
|
||||
<div className="player-wrapper">
|
||||
{currentVideoUrl ? (
|
||||
<VideoPlayer
|
||||
src={currentVideoUrl}
|
||||
poster={useDemo ? demoPoster : undefined}
|
||||
subtitles={demoSubtitles}
|
||||
keyboardShortcuts={true}
|
||||
pictureInPicture={true}
|
||||
theme={{
|
||||
primaryColor: '#ef4444',
|
||||
accentColor: '#dc2626',
|
||||
}}
|
||||
onPlay={() => console.log('Playing')}
|
||||
onPause={() => console.log('Paused')}
|
||||
onTimeUpdate={(time) => console.log('Time:', time)}
|
||||
/>
|
||||
) : (
|
||||
<div className="no-video">
|
||||
<p>Enter a video URL or use the demo video</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="controls-section">
|
||||
<div className="url-input">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Enter video URL (MP4, HLS)"
|
||||
value={videoUrl}
|
||||
onChange={(e) => setVideoUrl(e.target.value)}
|
||||
disabled={useDemo}
|
||||
/>
|
||||
<button
|
||||
onClick={() => setUseDemo(!useDemo)}
|
||||
className={useDemo ? 'active' : ''}
|
||||
>
|
||||
{useDemo ? 'Using Demo' : 'Use Demo'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="features-section">
|
||||
<h2>Features</h2>
|
||||
<div className="features-grid">
|
||||
<div className="feature">
|
||||
<h3>⌨️ Keyboard Shortcuts</h3>
|
||||
<ul>
|
||||
<li><kbd>Space</kbd> or <kbd>K</kbd> - Play/Pause</li>
|
||||
<li><kbd>←</kbd> / <kbd>→</kbd> - Seek 5s</li>
|
||||
<li><kbd>J</kbd> / <kbd>L</kbd> - Seek 10s</li>
|
||||
<li><kbd>↑</kbd> / <kbd>↓</kbd> - Volume</li>
|
||||
<li><kbd>M</kbd> - Mute/Unmute</li>
|
||||
<li><kbd>F</kbd> - Fullscreen</li>
|
||||
<li><kbd>P</kbd> - Picture-in-Picture</li>
|
||||
<li><kbd>0-9</kbd> - Jump to %</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div className="feature">
|
||||
<h3>📱 Touch Gestures</h3>
|
||||
<ul>
|
||||
<li>Tap - Play/Pause</li>
|
||||
<li>Double tap left - Rewind 10s</li>
|
||||
<li>Double tap right - Forward 10s</li>
|
||||
<li>Swipe left/right - Seek</li>
|
||||
<li>Swipe up/down - Volume</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div className="feature">
|
||||
<h3>🎨 Modern UI</h3>
|
||||
<ul>
|
||||
<li>Clean, minimalist design</li>
|
||||
<li>Smooth animations</li>
|
||||
<li>Custom red theme</li>
|
||||
<li>Auto-hiding controls</li>
|
||||
<li>Responsive layout</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div className="feature">
|
||||
<h3>🚀 Advanced Features</h3>
|
||||
<ul>
|
||||
<li>HLS streaming support</li>
|
||||
<li>HTTP Range Request (MP4)</li>
|
||||
<li>Subtitles (VTT, SRT)</li>
|
||||
<li>Multiple audio tracks</li>
|
||||
<li>Playback speed control</li>
|
||||
<li>Quality selector</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer className="app-footer">
|
||||
<p>Built with React, TypeScript, and Vite</p>
|
||||
<p>Zero runtime dependencies • ~8KB gzipped</p>
|
||||
</footer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
@@ -0,0 +1,9 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
)
|
||||
Reference in New Issue
Block a user