An HTML5 video player that supports HLS and DASH with a common API and skin.
—
The Tech system in Video.js provides an abstraction layer for different media playback technologies (HTML5, Flash, etc.), allowing for consistent player behavior across different playback engines and enabling custom tech implementations.
Register custom playback technologies for use in Video.js players.
/**
* Register a playback technology
* @param name - Tech name (used in techOrder option)
* @param tech - Tech class extending Tech base class
*/
videojs.registerTech(name: string, tech: typeof Tech): void;
/**
* Get registered tech class by name
* @param name - Tech name
* @returns Tech class or undefined
*/
videojs.getTech(name: string): typeof Tech | undefined;Usage Examples:
// Register custom tech
class CustomTech extends videojs.getTech('Tech') {
static isSupported() {
return true; // Check if this tech is supported
}
constructor(options, ready) {
super(options, ready);
this.setupCustomPlayback();
}
setupCustomPlayback() {
// Initialize custom playback engine
}
}
// Register the tech
videojs.registerTech('CustomTech', CustomTech);
// Use in player options
const player = videojs('my-video', {
techOrder: ['CustomTech', 'Html5']
});Core functionality that all tech implementations must provide.
/**
* Base Tech class for media playback technologies
*/
class Tech {
/**
* Create tech instance
* @param options - Tech options
* @param ready - Ready callback
*/
constructor(options?: TechOptions, ready?: () => void);
/**
* Check if this tech is supported in current environment
* @returns True if supported
*/
static isSupported(): boolean;
/**
* Check if tech can play given source
* @param source - Media source to check
* @returns Support level ('probably', 'maybe', or '')
*/
static canPlaySource(source: Source): string;
/**
* Check if tech can play given type
* @param type - MIME type to check
* @returns Support level ('probably', 'maybe', or '')
*/
static canPlayType(type: string): string;
/**
* Get tech features
* @returns Object describing tech capabilities
*/
static getFeatures(): TechFeatures;
}Standard playback methods that all techs must implement.
/**
* Start media playback
* @returns Promise that resolves when playback starts
*/
play(): Promise<void>;
/**
* Pause media playback
*/
pause(): void;
/**
* Check if media is paused
* @returns True if paused
*/
paused(): boolean;
/**
* Get current playback time
* @returns Current time in seconds
*/
currentTime(): number;
/**
* Set current playback time
* @param seconds - Time to seek to
*/
setCurrentTime(seconds: number): void;
/**
* Get media duration
* @returns Duration in seconds
*/
duration(): number;
/**
* Get buffered time ranges
* @returns TimeRanges object
*/
buffered(): TimeRanges;
/**
* Get volume level
* @returns Volume (0.0 to 1.0)
*/
volume(): number;
/**
* Set volume level
* @param level - Volume (0.0 to 1.0)
*/
setVolume(level: number): void;
/**
* Check if muted
* @returns True if muted
*/
muted(): boolean;
/**
* Set muted state
* @param muted - True to mute
*/
setMuted(muted: boolean): void;
/**
* Get playback rate
* @returns Current playback rate
*/
playbackRate(): number;
/**
* Set playback rate
* @param rate - Playback rate (1.0 = normal)
*/
setPlaybackRate(rate: number): void;Methods for loading and managing media sources.
/**
* Set media source
* @param source - Source object or URL
*/
setSrc(source: Source | string): void;
/**
* Get current source
* @returns Current source object
*/
src(): Source;
/**
* Get current source URL
* @returns Current source URL
*/
currentSrc(): string;
/**
* Load media source
*/
load(): void;
/**
* Reset tech to initial state
*/
reset(): void;Control video dimensions and display properties.
/**
* Get video width
* @returns Width in pixels
*/
videoWidth(): number;
/**
* Get video height
* @returns Height in pixels
*/
videoHeight(): number;
/**
* Set poster image
* @param src - Poster image URL
*/
setPoster(src: string): void;The default HTML5 tech implementation with extensive browser support.
/**
* HTML5 tech using native video/audio elements
*/
class Html5 extends Tech {
/**
* HTML5 tech options
*/
static readonly Options: Html5Options;
/**
* Supported events
*/
static readonly Events: string[];
/**
* Check HTML5 video support
* @returns True if HTML5 video is supported
*/
static isSupported(): boolean;
/**
* Get native video element
* @returns HTML video element
*/
el(): HTMLVideoElement;
}Usage Examples:
// HTML5 tech options
const player = videojs('my-video', {
html5: {
preloadTextTracks: false,
nativeAudioTracks: false,
nativeVideoTracks: false,
nativeTextTracks: false
}
});
// Access HTML5 tech directly
const html5Tech = player.tech({ IWillNotUseThisInPlugins: true });
const videoElement = html5Tech.el();Intercept and modify tech operations using middleware.
/**
* Register middleware for tech operations
* @param type - Middleware type or tech name
* @param middleware - Middleware function or object
*/
videojs.use(type: string, middleware: MiddlewareFunction | MiddlewareObject): void;
/**
* Middleware terminator object
*/
videojs.middleware.TERMINATOR: object;Usage Examples:
// Source middleware - modify sources before loading
videojs.use('*', (player) => {
return {
setSource(srcObj, next) {
// Modify source before setting
if (srcObj.src.includes('example.com')) {
srcObj.src = srcObj.src.replace('http://', 'https://');
}
next(null, srcObj);
}
};
});
// Play middleware - intercept play calls
videojs.use('Html5', (player) => {
return {
callPlay() {
console.log('Play intercepted');
// Return terminator to prevent default play
return videojs.middleware.TERMINATOR;
}
};
});Example of implementing a custom tech for specialized playback needs.
Usage Examples:
// Custom streaming tech
class StreamingTech extends videojs.getTech('Tech') {
constructor(options, ready) {
super(options, ready);
this.player_ = options.player;
this.streamingEngine = null;
this.setupStreaming();
}
static isSupported() {
return window.StreamingEngine && window.StreamingEngine.isSupported();
}
static canPlaySource(source) {
return source.type === 'application/x-custom-stream' ? 'probably' : '';
}
setupStreaming() {
this.streamingEngine = new window.StreamingEngine();
this.streamingEngine.on('loaded', () => {
this.trigger('loadedmetadata');
this.trigger('canplay');
});
}
play() {
return this.streamingEngine.play();
}
pause() {
this.streamingEngine.pause();
}
paused() {
return this.streamingEngine.isPaused();
}
setSrc(source) {
this.streamingEngine.load(source.src);
}
dispose() {
if (this.streamingEngine) {
this.streamingEngine.dispose();
}
super.dispose();
}
}
// Register custom tech
videojs.registerTech('StreamingTech', StreamingTech);Tech capabilities that can be queried by the player.
/**
* Tech feature flags
*/
interface TechFeatures {
// Volume control support
volumeControl: boolean;
// Fullscreen support
fullscreenResize: boolean;
// Progress events support
progressEvents: boolean;
// Time update events support
timeupdateEvents: boolean;
// Playback rate support
playbackRates: boolean;
// Audio track support
audioTracks: boolean;
// Video track support
videoTracks: boolean;
// Text track support
textTracks: boolean;
// Native text track support
nativeTextTracks: boolean;
// Source handler support
sourceHandler: boolean;
}interface TechOptions {
player?: Player;
source?: Source;
[key: string]: any;
}
interface Html5Options {
preloadTextTracks?: boolean;
nativeAudioTracks?: boolean;
nativeVideoTracks?: boolean;
nativeTextTracks?: boolean;
[key: string]: any;
}
interface Source {
src: string;
type: string;
[key: string]: any;
}
interface MiddlewareObject {
callPlay?(): any;
callPause?(): any;
setSource?(src: Source, next: (error?: any, src?: Source) => void): void;
setTech?(tech: Tech, next: (error?: any, tech?: Tech) => void): void;
play?(cancelled: boolean, value: any): any;
pause?(cancelled: boolean, value: any): any;
}
type MiddlewareFunction = (player: Player) => MiddlewareObject;
interface Tech {
// Core playback
play(): Promise<void>;
pause(): void;
paused(): boolean;
// Time and seeking
currentTime(): number;
setCurrentTime(seconds: number): void;
duration(): number;
buffered(): TimeRanges;
// Audio
volume(): number;
setVolume(level: number): void;
muted(): boolean;
setMuted(muted: boolean): void;
// Sources
setSrc(source: Source | string): void;
src(): Source;
load(): void;
// Dimensions
videoWidth(): number;
videoHeight(): number;
// Lifecycle
dispose(): void;
}Install with Tessl CLI
npx tessl i tessl/npm-video-js