strataplayer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/lib.d.ts +229 -0
- package/dist/logo.png +0 -0
- package/dist/strataplayer.es.js +51286 -0
- package/dist/strataplayer.es.js.map +1 -0
- package/dist/strataplayer.umd.js +603 -0
- package/dist/strataplayer.umd.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 StrataPlayer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# StrataPlayer
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="public/logo.png" alt="StrataPlayer Logo" width="128" />
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<strong>A robust, secure, and production-grade video player built for the modern web.</strong>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://github.com/dev-AshishRanjan/StrataPlayer/blob/main/LICENSE">
|
|
12
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://react.dev">
|
|
15
|
+
<img src="https://img.shields.io/badge/react-19.0-blue" alt="React" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://www.typescriptlang.org/">
|
|
18
|
+
<img src="https://img.shields.io/badge/typescript-5.0-blue" alt="TypeScript" />
|
|
19
|
+
</a>
|
|
20
|
+
</p>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
StrataPlayer is a highly customizable, high-performance HTML5 video player designed for React applications. It features a lightweight core with a plugin architecture, advanced subtitle management, robust error handling, and a sleek, themeable UI powered by Tailwind CSS.
|
|
26
|
+
|
|
27
|
+
It supports HLS (HTTP Live Streaming) out of the box via `hls.js`, along with standard MP4/WebM formats, making it suitable for VOD, live streaming, and complex media applications.
|
|
28
|
+
|
|
29
|
+
## ✨ Features
|
|
30
|
+
|
|
31
|
+
### Core Playback
|
|
32
|
+
|
|
33
|
+
- **Multi-Format Support:** Seamlessly plays HLS (`.m3u8`), MP4, WebM, and DASH (via plugin extension).
|
|
34
|
+
- **Robust Error Handling:** Exponential backoff retry logic for network failures and stream interruptions.
|
|
35
|
+
- **Adaptive Bitrate:** Automatic quality switching with manual override controls.
|
|
36
|
+
- **Audio Engine:** Built-in Web Audio API integration for **Audio Boost** (up to 300% volume).
|
|
37
|
+
|
|
38
|
+
### User Interface & Experience
|
|
39
|
+
|
|
40
|
+
- **Fully Themeable:** Includes 4 built-in themes (Default, Pixel, Game, Hacker) and custom accent color support.
|
|
41
|
+
- **Responsive Controls:** Mobile-friendly touch controls and gesture support (double tap to seek).
|
|
42
|
+
- **Keyboard Shortcuts:** Full accessibility support with standard hotkeys (`Space`, `F`, `M`, Arrows).
|
|
43
|
+
- **Picture-in-Picture:** Native PiP support for multitasking.
|
|
44
|
+
- **Chromecast Support:** Built-in Google Cast integration.
|
|
45
|
+
|
|
46
|
+
### Advanced Subtitles
|
|
47
|
+
|
|
48
|
+
- **Custom Rendering:** High-performance canvas/DOM-based subtitle rendering.
|
|
49
|
+
- **Full Customization:** Users can adjust font size, color, background opacity, blur, and offsets.
|
|
50
|
+
- **Synchronization:** Manual subtitle offset adjustment to fix out-of-sync captions.
|
|
51
|
+
- **Local Upload:** Support for drag-and-drop `.vtt` and `.srt` files.
|
|
52
|
+
|
|
53
|
+
### Developer Experience
|
|
54
|
+
|
|
55
|
+
- **React 19 Ready:** Built with the latest React patterns (Hooks, `useSyncExternalStore`).
|
|
56
|
+
- **State Management:** Lightweight, external store (`NanoStore`) for high-performance updates without re-renders.
|
|
57
|
+
- **Plugin System:** Easily extend functionality without bloating the core.
|
|
58
|
+
- **TypeScript:** 100% type-safe.
|
|
59
|
+
|
|
60
|
+
## 🚀 Getting Started
|
|
61
|
+
|
|
62
|
+
### Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Clone the repository
|
|
66
|
+
git clone https://github.com/dev-AshishRanjan/StrataPlayer.git
|
|
67
|
+
|
|
68
|
+
# Navigate to project directory
|
|
69
|
+
cd StrataPlayer
|
|
70
|
+
|
|
71
|
+
# Install dependencies
|
|
72
|
+
npm install
|
|
73
|
+
|
|
74
|
+
# Start the development server
|
|
75
|
+
npm run dev
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Basic Usage
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { StrataPlayer } from "./ui/StrataPlayer";
|
|
82
|
+
|
|
83
|
+
const App = () => {
|
|
84
|
+
return (
|
|
85
|
+
<div className="w-full max-w-4xl mx-auto">
|
|
86
|
+
<StrataPlayer
|
|
87
|
+
src="https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"
|
|
88
|
+
autoPlay={false}
|
|
89
|
+
theme="default"
|
|
90
|
+
themeColor="#6366f1"
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Advanced Usage (Sources & Tracks)
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
<StrataPlayer
|
|
101
|
+
sources={[
|
|
102
|
+
{ name: "HLS Master", url: "https://example.com/master.m3u8", type: "hls" },
|
|
103
|
+
{ name: "MP4 Fallback", url: "https://example.com/video.mp4", type: "mp4" },
|
|
104
|
+
]}
|
|
105
|
+
poster="https://example.com/poster.jpg"
|
|
106
|
+
thumbnails="https://example.com/thumbnails.vtt"
|
|
107
|
+
textTracks={[
|
|
108
|
+
{
|
|
109
|
+
kind: "subtitles",
|
|
110
|
+
label: "English",
|
|
111
|
+
src: "/subs/en.vtt",
|
|
112
|
+
srcLang: "en",
|
|
113
|
+
default: true,
|
|
114
|
+
},
|
|
115
|
+
]}
|
|
116
|
+
/>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## ⌨️ Keyboard Shortcuts
|
|
120
|
+
|
|
121
|
+
| Key | Action |
|
|
122
|
+
| ------------- | ----------------- |
|
|
123
|
+
| `Space` / `K` | Play / Pause |
|
|
124
|
+
| `F` | Toggle Fullscreen |
|
|
125
|
+
| `M` | Toggle Mute |
|
|
126
|
+
| `Arrow Right` | Seek Forward 5s |
|
|
127
|
+
| `Arrow Left` | Seek Backward 5s |
|
|
128
|
+
| `Arrow Up` | Increase Volume |
|
|
129
|
+
| `Arrow Down` | Decrease Volume |
|
|
130
|
+
|
|
131
|
+
## 🎨 Themes
|
|
132
|
+
|
|
133
|
+
StrataPlayer comes with preset themes that can be applied via props or changed at runtime by the user:
|
|
134
|
+
|
|
135
|
+
- **Default:** Modern, clean, and professional (Inter font).
|
|
136
|
+
- **Pixel:** Retro gaming aesthetic (Press Start 2P font).
|
|
137
|
+
- **Game:** Cinematic RPG style (Cinzel font).
|
|
138
|
+
- **Hacker:** Terminal/Cyberpunk aesthetic (JetBrains Mono font).
|
|
139
|
+
|
|
140
|
+
## 🤝 Contributing
|
|
141
|
+
|
|
142
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
143
|
+
|
|
144
|
+
1. Fork the project
|
|
145
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
146
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
147
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
148
|
+
5. Open a Pull Request
|
|
149
|
+
|
|
150
|
+
## 📄 License
|
|
151
|
+
|
|
152
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
<div align="center">
|
|
157
|
+
Built with ❤️ by <a href="https://github.com/dev-AshishRanjan">Ashish Ranjan</a>
|
|
158
|
+
</div>
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
declare class EventBus {
|
|
4
|
+
private events;
|
|
5
|
+
constructor();
|
|
6
|
+
on<T>(event: string, callback: EventCallback<T>): () => void;
|
|
7
|
+
off<T>(event: string, callback: EventCallback<T>): void;
|
|
8
|
+
emit<T>(event: string, data?: T): void;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare type EventCallback<T = any> = (data: T) => void;
|
|
13
|
+
|
|
14
|
+
export declare class HlsPlugin implements IPlugin {
|
|
15
|
+
name: string;
|
|
16
|
+
private hls;
|
|
17
|
+
private core;
|
|
18
|
+
init(core: StrataCore): void;
|
|
19
|
+
private loadHls;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare interface IPlugin {
|
|
24
|
+
name: string;
|
|
25
|
+
init(core: StrataCore): void;
|
|
26
|
+
destroy?(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare type Listener<T> = (state: T, prevState: T) => void;
|
|
30
|
+
|
|
31
|
+
export declare const mountStrataPlayer: (container: HTMLElement, props: any) => StrataPlayerInstance;
|
|
32
|
+
|
|
33
|
+
declare class NanoStore<T> {
|
|
34
|
+
private state;
|
|
35
|
+
private listeners;
|
|
36
|
+
constructor(initialState: T);
|
|
37
|
+
get(): T;
|
|
38
|
+
setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;
|
|
39
|
+
subscribe(listener: Listener<T>): () => void;
|
|
40
|
+
destroy(): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare interface Notification_2 {
|
|
44
|
+
id: string;
|
|
45
|
+
message: string;
|
|
46
|
+
type: 'info' | 'success' | 'warning' | 'error' | 'loading';
|
|
47
|
+
duration?: number;
|
|
48
|
+
progress?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare interface PlayerSource {
|
|
52
|
+
url: string;
|
|
53
|
+
type?: 'hls' | 'mp4' | 'webm' | 'dash' | string;
|
|
54
|
+
name?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare interface PlayerState {
|
|
58
|
+
isPlaying: boolean;
|
|
59
|
+
isBuffering: boolean;
|
|
60
|
+
currentTime: number;
|
|
61
|
+
duration: number;
|
|
62
|
+
buffered: {
|
|
63
|
+
start: number;
|
|
64
|
+
end: number;
|
|
65
|
+
}[];
|
|
66
|
+
volume: number;
|
|
67
|
+
isMuted: boolean;
|
|
68
|
+
audioGain: number;
|
|
69
|
+
playbackRate: number;
|
|
70
|
+
qualityLevels: {
|
|
71
|
+
height: number;
|
|
72
|
+
bitrate: number;
|
|
73
|
+
index: number;
|
|
74
|
+
}[];
|
|
75
|
+
currentQuality: number;
|
|
76
|
+
audioTracks: {
|
|
77
|
+
label: string;
|
|
78
|
+
language: string;
|
|
79
|
+
index: number;
|
|
80
|
+
}[];
|
|
81
|
+
currentAudioTrack: number;
|
|
82
|
+
error: string | null;
|
|
83
|
+
isFullscreen: boolean;
|
|
84
|
+
isPip: boolean;
|
|
85
|
+
subtitleTracks: {
|
|
86
|
+
label: string;
|
|
87
|
+
language: string;
|
|
88
|
+
index: number;
|
|
89
|
+
}[];
|
|
90
|
+
currentSubtitle: number;
|
|
91
|
+
subtitleOffset: number;
|
|
92
|
+
subtitleSettings: SubtitleSettings;
|
|
93
|
+
activeCues: string[];
|
|
94
|
+
viewMode: 'normal' | 'theater' | 'pip';
|
|
95
|
+
notifications: Notification_2[];
|
|
96
|
+
iconSize: 'small' | 'medium' | 'large';
|
|
97
|
+
themeColor: string;
|
|
98
|
+
theme: PlayerTheme;
|
|
99
|
+
sources: PlayerSource[];
|
|
100
|
+
currentSourceIndex: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare type PlayerTheme = 'default' | 'pixel' | 'game' | 'hacker';
|
|
104
|
+
|
|
105
|
+
export declare interface StrataConfig {
|
|
106
|
+
volume?: number;
|
|
107
|
+
muted?: boolean;
|
|
108
|
+
playbackRate?: number;
|
|
109
|
+
audioGain?: number;
|
|
110
|
+
theme?: PlayerTheme;
|
|
111
|
+
themeColor?: string;
|
|
112
|
+
iconSize?: 'small' | 'medium' | 'large';
|
|
113
|
+
subtitleSettings?: Partial<SubtitleSettings>;
|
|
114
|
+
disablePersistence?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export declare class StrataCore {
|
|
118
|
+
video: HTMLVideoElement;
|
|
119
|
+
container: HTMLElement | null;
|
|
120
|
+
events: EventBus;
|
|
121
|
+
store: NanoStore<PlayerState>;
|
|
122
|
+
private plugins;
|
|
123
|
+
private audioEngine;
|
|
124
|
+
private config;
|
|
125
|
+
private retryCount;
|
|
126
|
+
private maxRetries;
|
|
127
|
+
private retryTimer;
|
|
128
|
+
private currentSource;
|
|
129
|
+
private currentSrc;
|
|
130
|
+
private currentTracks;
|
|
131
|
+
private castInitialized;
|
|
132
|
+
private boundCueChange;
|
|
133
|
+
private boundFullscreenChange;
|
|
134
|
+
constructor(config?: StrataConfig, videoElement?: HTMLVideoElement);
|
|
135
|
+
private initVideoListeners;
|
|
136
|
+
triggerError(message: string, isFatal?: boolean): void;
|
|
137
|
+
private handleError;
|
|
138
|
+
private updateBuffer;
|
|
139
|
+
private updateSubtitles;
|
|
140
|
+
fetchWithRetry(url: string, retries?: number): Promise<Response>;
|
|
141
|
+
attach(container: HTMLElement): void;
|
|
142
|
+
use(plugin: IPlugin): void;
|
|
143
|
+
setSources(sources: PlayerSource[], tracks?: TextTrackConfig[]): void;
|
|
144
|
+
switchSource(index: number): void;
|
|
145
|
+
load(source: PlayerSource | string, tracks?: TextTrackConfig[], isRetry?: boolean): void;
|
|
146
|
+
addTextTrack(file: File, label: string): void;
|
|
147
|
+
private addTextTrackInternal;
|
|
148
|
+
play(): Promise<void>;
|
|
149
|
+
pause(): void;
|
|
150
|
+
togglePlay(): void;
|
|
151
|
+
seek(time: number): void;
|
|
152
|
+
skip(seconds: number): void;
|
|
153
|
+
setVolume(vol: number): void;
|
|
154
|
+
toggleMute(): void;
|
|
155
|
+
setAudioGain(gain: number): void;
|
|
156
|
+
setQuality(index: number): void;
|
|
157
|
+
setAudioTrack(index: number): void;
|
|
158
|
+
toggleFullscreen(): void;
|
|
159
|
+
togglePip(): void;
|
|
160
|
+
private initCast;
|
|
161
|
+
requestCast(): void;
|
|
162
|
+
private loadMediaToCast;
|
|
163
|
+
private handleCueChange;
|
|
164
|
+
setSubtitle(index: number): void;
|
|
165
|
+
updateSubtitleSettings(settings: Partial<SubtitleSettings>): void;
|
|
166
|
+
resetSubtitleSettings(): void;
|
|
167
|
+
setSubtitleOffset(offset: number): void;
|
|
168
|
+
download(): Promise<void>;
|
|
169
|
+
notify(n: Omit<Notification_2, 'id'> & {
|
|
170
|
+
id?: string;
|
|
171
|
+
}): string;
|
|
172
|
+
removeNotification(id: string): void;
|
|
173
|
+
setAppearance(settings: {
|
|
174
|
+
iconSize?: 'small' | 'medium' | 'large';
|
|
175
|
+
themeColor?: string;
|
|
176
|
+
theme?: PlayerTheme;
|
|
177
|
+
}): void;
|
|
178
|
+
destroy(): void;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export declare const StrataPlayer: (props: StrataPlayerProps) => JSX.Element;
|
|
182
|
+
|
|
183
|
+
export declare interface StrataPlayerInstance {
|
|
184
|
+
unmount: () => void;
|
|
185
|
+
update: (props: any) => void;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare interface StrataPlayerProps extends StrataConfig {
|
|
189
|
+
src?: string;
|
|
190
|
+
sources?: PlayerSource[];
|
|
191
|
+
poster?: string;
|
|
192
|
+
autoPlay?: boolean;
|
|
193
|
+
thumbnails?: string;
|
|
194
|
+
textTracks?: TextTrackConfig[];
|
|
195
|
+
plugins?: IPlugin[];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
declare interface SubtitleSettings {
|
|
199
|
+
useNative: boolean;
|
|
200
|
+
fixCapitalization: boolean;
|
|
201
|
+
backgroundOpacity: number;
|
|
202
|
+
backgroundBlur: boolean;
|
|
203
|
+
backgroundBlurAmount: number;
|
|
204
|
+
textSize: number;
|
|
205
|
+
textStyle: 'none' | 'outline' | 'raised' | 'depressed' | 'shadow';
|
|
206
|
+
isBold: boolean;
|
|
207
|
+
textColor: string;
|
|
208
|
+
verticalOffset: number;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export declare interface TextTrackConfig {
|
|
212
|
+
kind: 'subtitles' | 'captions' | 'descriptions' | 'chapters' | 'metadata';
|
|
213
|
+
label: string;
|
|
214
|
+
src: string;
|
|
215
|
+
srcLang: string;
|
|
216
|
+
default?: boolean;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { }
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
declare module 'react' {
|
|
223
|
+
namespace JSX {
|
|
224
|
+
interface IntrinsicElements {
|
|
225
|
+
'google-cast-launcher': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
package/dist/logo.png
ADDED
|
Binary file
|