@zezosoft/react-player
Version:
A lightweight and customizable video player by Zezosoft, built for seamless streaming with advanced controls, adaptive playback, and modern UI. Perfect for web and React applications.
79 lines (78 loc) • 3.12 kB
TypeScript
import Hls from 'hls.js';
import * as dashjs from 'dashjs';
export type StreamType = 'hls' | 'dash' | 'mp4' | 'other';
/**
* Video Quality Management Utility
* Provides a unified interface for quality switching across HLS.js and DASH.js
*
* This utility follows OTT-grade best practices for smooth quality switching:
* - Immediate quality changes without playback interruption
* - Proper ABR (Adaptive Bitrate) control
* - Error handling and fallback mechanisms
* - Support for both manual and auto quality modes
*/
export declare class QualityManager {
/**
* Set video quality for HLS streams with OTT-grade smoothness
*
* Best practices implemented:
* 1. Use currentLevel for immediate quality change
* 2. Use autoLevelCapping to prevent ABR from switching back
* 3. Use nextLevel to ensure next segment uses selected quality
* 4. Handle edge cases and errors gracefully
*
* @param hlsInstance HLS.js instance (null for native HLS, undefined when not available)
* @param levelIndex Quality level index (-1 for auto)
*/
static setHlsQuality(hlsInstance: Hls | null | undefined, levelIndex: number): void;
/**
* Set video quality for DASH streams with OTT-grade smoothness
*
* Best practices implemented:
* 1. Use autoSwitchBitrate settings to control ABR behavior
* 2. Use setRepresentationForTypeById for immediate quality change
* 3. Handle representation discovery and selection properly
* 4. Provide visual feedback through console logs
*
* @param dashInstance DASH.js instance
* @param qualityId Quality level ID (undefined/null for auto)
*/
static setDashQuality(dashInstance: dashjs.MediaPlayerClass, qualityId: string | null | undefined): void;
/**
* Get available quality levels for HLS with proper error handling
*
* @param hlsInstance HLS.js instance
* @returns Array of quality level objects
*/
static getHlsQualityLevels(hlsInstance: Hls): Array<{
height: number;
bitrate?: number;
originalIndex: number;
}>;
/**
* Get available quality levels for DASH with proper error handling
*
* @param dashInstance DASH.js instance
* @returns Array of quality level objects
*/
static getDashQualityLevels(dashInstance: dashjs.MediaPlayerClass): Array<{
height: number;
bitrate?: number;
id: string;
}>;
/**
* Unified quality setting function that works with both HLS and DASH
* Provides a single interface for quality management across streaming technologies
*
* @param streamType Type of stream (hls, dash, etc.)
* @param qualityIdentifier Quality level identifier (index for HLS, ID for DASH)
*/
static setQuality(streamType: StreamType, qualityIdentifier: string | number): void;
/**
* Enable auto quality switching for the current stream type
*
* @param streamType Type of stream (hls, dash, etc.)
*/
static setAutoQuality(streamType: StreamType): void;
}
export default QualityManager;