# @source/player
`@source/player` is a modular, highly customizable React video player library for VOD and live streaming workflows.
Current package version: `3.1.0`.
## Why this player
- React-first component architecture (`VideoPlayer`, `PlayerProvider`, `usePlayerContext`)
- Protocol-aware playback with automatic detection (`native`, `hls`, `rtmp/flv`, `mpegts`)
- Runtime loading for streaming engines (`hls.js`, `flv.js`, `mpegts.js`) with CDN fallback
- Built-in settings UI for speed, quality, audio track, subtitles, and subtitle style editor
- Slot-style customization (`children`, `controlsLeftExtra`, `controlsRightExtra`)
- Configurable keyboard and touch interaction
- TypeScript-first API with strong exported types and an imperative ref handle
## Installation
This package is published to a private registry.
1. Configure `.npmrc`:
```ini
@source:registry=https://gits.hibna.com.tr/api/packages/hibna/npm/
//gits.hibna.com.tr/api/packages/hibna/npm/:_authToken=${GITS_NPM_TOKEN}
```
2. Install:
```bash
npm install @source/player
# or
pnpm add @source/player
# or
yarn add @source/player
```
3. Ensure your app already has React and ReactDOM installed (`>=18`).
Optional local dependencies (if you prefer bundling instead of CDN fallback):
```bash
npm install hls.js flv.js mpegts.js
```
## Quick start
```tsx
import { VideoPlayer } from '@source/player'
import '@source/player/styles.css'
export function App() {
return
}
```
## Common usage scenarios
### 1. Standard VOD playback
```tsx
```
### 2. HLS playback with quality/audio menus
```tsx
console.log('quality', quality.label)}
/>
```
### 3. IPTV MPEG-TS stream
```tsx
```
### 4. Subtitle style editor with local persistence
```tsx
```
### 5. Modular control customization
```tsx
Bookmark}
controlsRightExtra={}
theme={{
primaryColor: '#22c55e',
accentColor: '#16a34a',
borderRadius: 18,
fontFamily: 'Manrope, sans-serif',
}}
/>
```
## API at a glance
Key `VideoPlayer` props:
- Playback: `src`, `protocol`, `autoplay`, `loop`, `muted`, `volume`, `playbackRate`, `currentTime`
- Media element config: `crossOrigin`, `preload`, `playsInline`, `controlsList`
- UI toggles: `controls`, `keyboardShortcuts`, `pictureInPicture`
- Customization: `theme`, `className`, `style`, `aspectRatio`, `playbackRates`
- Subtitles: `subtitles`, `subtitleStyle`, `subtitleStyleEditor`, `subtitlePosition`, `subtitleOffset`
- Extensibility: `children`, `controlsLeftExtra`, `controlsRightExtra`
- Input config: `keyboardShortcutConfig`, `touchConfig`
- Localization: `language`, `translations`
- Events: `onPlay`, `onPause`, `onEnded`, `onTimeUpdate`, `onError`, `onQualityChange`, `onBufferStart`, `onBufferEnd`, `onFirstPlay`, and more
## Imperative control via ref
```tsx
import { useRef } from 'react'
import { VideoPlayer, type VideoPlayerHandle } from '@source/player'
export function PlayerWithRef() {
const playerRef = useRef(null)
return (
<>
>
)
}
```
## Other exports
```ts
import {
PlayerErrorBoundary,
PlayerProvider,
usePlayerContext,
useKeyboardShortcuts,
useTouchGestures,
formatTime,
parseTime,
parseSRT,
createSubtitleBlobURL,
fetchSubtitle,
validateVideoURL,
checkVideoCORS,
initializePolyfills,
features,
getTranslations,
detectBrowserLanguage,
} from '@source/player'
```
## Documentation map
For complete details, see `DOCUMENTATION.md`:
- Full `VideoPlayerProps` and event reference
- Streaming architecture (HLS/RTMP-FLV/MPEG-TS)
- Subtitle rendering and style editor internals
- Theme tokens and CSS variable mapping
- Keyboard and touch behavior
- Error handling and browser caveats
## Development
```bash
npm install
npm run dev
npm run test:run
npm run build:lib
```
Useful scripts:
- `npm run lint`
- `npm run typecheck`
- `npm run validate:publish`
## License
MIT