# @source/player `@source/player` is a modular, highly customizable React media player library for VOD, live streaming, animated images, and audio playback workflows. Current package version: `3.2.0`. ## Why this player - React-first component architecture (`VideoPlayer`, `AudioPlayer`, `PlayerProvider`, `usePlayerContext`) - Protocol-aware playback with automatic detection (`native`, `hls`, `rtmp/flv`, `mpegts`) - Built-in animated image support (`.gif`, `.webp`, `.apng`, `.avif`) with minimal render path - Dedicated audio player component for `.mp3`, `.wav`, `.flac`, `.m4a`, and similar formats - 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', }} /> ``` ### 6. Animated image playback (GIF / WebP / APNG / AVIF) ```tsx ``` ### 7. Dedicated audio player ```tsx import { AudioPlayer } from '@source/player' ``` ## API at a glance Key `VideoPlayer` props: - Playback: `src`, `mediaType`, `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 Key `AudioPlayer` props: - Source + playback: `src`, `autoplay`, `loop`, `muted`, `volume`, `playbackRate`, `currentTime` - UI + customization: `controls`, `keyboardShortcuts`, `playbackRates`, `theme`, `className`, `style` - Metadata + slots: `title`, `subtitle`, `artwork`, `children`, `controlsLeftExtra`, `controlsRightExtra` - Localization + events: `language`, `translations`, `onPlay`, `onPause`, `onTimeUpdate`, `onError`, 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 { AudioPlayer, PlayerErrorBoundary, PlayerProvider, usePlayerContext, useKeyboardShortcuts, useTouchGestures, formatTime, parseTime, parseSRT, createSubtitleBlobURL, fetchSubtitle, validateVideoURL, checkVideoCORS, initializePolyfills, features, detectPlayerMediaType, isAnimatedImageSource, isAudioSource, getTranslations, detectBrowserLanguage, } from '@source/player' ``` ## Documentation map For complete details, see `DOCUMENTATION.md`: - Full `VideoPlayerProps` and event reference - Full `AudioPlayerProps` and event reference - Streaming architecture (HLS/RTMP-FLV/MPEG-TS) - Animated image detection and render behavior - 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