CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-video-js

An HTML5 video player that supports HLS and DASH with a common API and skin.

Pending
Overview
Eval results
Files

player.mddocs/

Player API

The Player is the core class in Video.js that provides complete media playback control and serves as the central coordinator for all video player functionality.

Capabilities

Player Creation

Create and configure video player instances with comprehensive options.

/**
 * Create or retrieve a video player instance
 * @param id - Video element or element ID 
 * @param options - Player configuration options
 * @param ready - Callback when player is ready
 * @returns Player instance
 */
function videojs(id: string | Element, options?: VideoJsOptions, ready?: () => void): Player;

/**
 * Get existing player instance without creating new one
 * @param id - Video element or element ID
 * @returns Player instance or undefined
 */
videojs.getPlayer(id: string | Element): Player | undefined;

/**
 * Get all created players
 * @returns Object with all players keyed by ID
 */
videojs.getPlayers(): Record<string, Player>;

/**
 * Get array of all active player instances
 * @returns Array of player instances
 */
videojs.getAllPlayers(): Player[];

Usage Examples:

// Basic player creation
const player = videojs("my-video");

// Player with options
const player = videojs("my-video", {
  controls: true,
  fluid: true,
  aspectRatio: "16:9",
  autoplay: false,
  preload: "metadata",
  sources: [{
    src: "path/to/video.mp4", 
    type: "video/mp4"
  }]
});

// Player with ready callback
const player = videojs("my-video", {}, () => {
  console.log("Player is ready!");
});

// Get existing player
const existingPlayer = videojs.getPlayer("my-video");

Playback Control

Control media playback including play, pause, seeking, and speed adjustment.

/**
 * Start playback
 * @returns Promise that resolves when playback starts
 */
play(): Promise<void>;

/**
 * Pause playback
 */
pause(): void;

/**
 * Check if player is paused
 * @returns True if paused
 */
paused(): boolean;

/**
 * Get current playback time in seconds
 * @returns Current time
 */
currentTime(): number;

/**
 * Set current playback time
 * @param seconds - Time to seek to
 */
currentTime(seconds: number): void;

/**
 * Get media duration in seconds
 * @returns Duration or NaN if unknown
 */
duration(): number;

/**
 * Get remaining playback time
 * @returns Remaining time in seconds
 */
remainingTime(): number;

/**
 * Get playback rate
 * @returns Current playback rate (1.0 = normal speed)
 */
playbackRate(): number;

/**
 * Set playback rate
 * @param rate - Playback rate (0.5 = half speed, 2.0 = double speed)
 */
playbackRate(rate: number): void;

Usage Examples:

// Basic playback control
await player.play();
player.pause();

// Check playback state
if (player.paused()) {
  console.log("Player is paused");
}

// Seeking
player.currentTime(30); // Seek to 30 seconds
console.log("Current time:", player.currentTime());
console.log("Duration:", player.duration());
console.log("Remaining:", player.remainingTime());

// Speed control
player.playbackRate(1.5); // Play at 1.5x speed

Audio Control

Manage audio volume and muting functionality.

/**
 * Get volume level
 * @returns Volume (0.0 to 1.0)
 */
volume(): number;

/**
 * Set volume level
 * @param level - Volume level (0.0 to 1.0)
 */
volume(level: number): void;

/**
 * Check if audio is muted
 * @returns True if muted
 */
muted(): boolean;

/**
 * Set muted state
 * @param muted - True to mute, false to unmute
 */
muted(muted: boolean): void;

Usage Examples:

// Volume control
player.volume(0.8); // Set volume to 80%
console.log("Volume:", player.volume());

// Muting
player.muted(true); // Mute audio
player.muted(false); // Unmute audio
console.log("Is muted:", player.muted());

Source Management

Load and manage media sources with support for multiple formats and streaming.

/**
 * Get current source(s)
 * @returns Array of current sources
 */
src(): Source[];

/**
 * Set media source(s)
 * @param source - Source URL, source object, or array of sources
 */
src(source: string | Source | Source[]): void;

/**
 * Get current source URL  
 * @returns Current source URL
 */
currentSrc(): string;

/**
 * Load new source and reset player
 */
load(): void;

/**
 * Reset player to initial state
 */
reset(): void;

Usage Examples:

// Set single source
player.src("path/to/video.mp4");

// Set source with type
player.src({
  src: "path/to/video.mp4",
  type: "video/mp4"
});

// Set multiple sources for format fallback
player.src([
  { src: "path/to/video.webm", type: "video/webm" },
  { src: "path/to/video.mp4", type: "video/mp4" },
  { src: "path/to/video.ogv", type: "video/ogg" }
]);

// Get current sources
const sources = player.src();
console.log("Current source:", player.currentSrc());

// Reload with new source
player.load();

Poster Management

Manage poster images displayed before playback begins.

/**
 * Get poster image URL
 * @returns Poster URL
 */
poster(): string;

/**
 * Set poster image URL
 * @param src - Poster image URL
 */
poster(src: string): void;

Dimensions and Display

Control player size, aspect ratio, and display modes.

/**
 * Get player width
 * @returns Width in pixels
 */
width(): number;

/**
 * Set player width
 * @param width - Width in pixels
 */
width(width: number): void;

/**
 * Get player height
 * @returns Height in pixels
 */
height(): number;

/**
 * Set player height  
 * @param height - Height in pixels
 */
height(height: number): void;

/**
 * Set both width and height
 * @param width - Width in pixels
 * @param height - Height in pixels
 */
dimensions(width: number, height: number): void;

/**
 * Get/set responsive fluid mode
 * @param bool - True to enable fluid mode
 * @returns Current fluid state or this for chaining
 */
fluid(bool?: boolean): boolean | Player;

/**
 * Get/set aspect ratio
 * @param ratio - Aspect ratio string (e.g., "16:9")
 * @returns Current aspect ratio or this for chaining
 */
aspectRatio(ratio?: string): string | Player;

Usage Examples:

// Fixed dimensions
player.width(800);
player.height(450);
player.dimensions(800, 450);

// Responsive/fluid sizing
player.fluid(true);
player.aspectRatio("16:9");

// Get dimensions
console.log("Size:", player.width(), "x", player.height());

Fullscreen Support

Manage fullscreen display with comprehensive browser support.

/**
 * Check if player is in fullscreen mode
 * @returns True if in fullscreen
 */
isFullscreen(): boolean;

/**
 * Request fullscreen mode
 * @returns Promise that resolves when fullscreen is entered
 */
requestFullscreen(): Promise<void>;

/**
 * Exit fullscreen mode
 * @returns Promise that resolves when fullscreen is exited  
 */
exitFullscreen(): Promise<void>;

/**
 * Check if fullscreen is supported
 * @returns True if fullscreen is supported
 */
supportsFullScreen(): boolean;

Usage Examples:

// Fullscreen control
if (player.supportsFullScreen()) {
  await player.requestFullscreen();
  console.log("In fullscreen:", player.isFullscreen());
  
  // Exit fullscreen
  await player.exitFullscreen();
}

Player State and Information

Access player state, buffering information, and technical details.

/**
 * Check if player is ready
 * @returns True if ready
 */
readyState(): number;

/**
 * Get buffered time ranges
 * @returns TimeRanges object
 */
buffered(): TimeRanges;

/**
 * Get percentage of video buffered
 * @returns Buffered percentage (0-100)
 */
bufferedPercent(): number;

/**
 * Check if media is seeking
 * @returns True if seeking
 */
seeking(): boolean;

/**
 * Check if media has ended
 * @returns True if ended
 */
ended(): boolean;

/**
 * Get network state
 * @returns Network state constant
 */
networkState(): number;

/**
 * Get error object if error occurred
 * @returns MediaError object or null
 */
error(): MediaError | null;

Lifecycle Management

Manage player lifecycle including initialization and cleanup.

/**
 * Execute callback when player is ready
 * @param callback - Function to call when ready
 */
ready(callback: () => void): void;

/**
 * Dispose of player and clean up resources
 */
dispose(): void;

/**
 * Check if player has been disposed
 * @returns True if disposed
 */
isDisposed(): boolean;

Usage Examples:

// Wait for player ready
player.ready(() => {
  console.log("Player is ready!");
  console.log("Duration:", player.duration());
});

// Clean up when done
player.dispose();

Types

interface VideoJsOptions {
  controls?: boolean;
  fluid?: boolean;
  responsive?: boolean;
  aspectRatio?: string;
  width?: number;
  height?: number;
  autoplay?: boolean | string;
  preload?: "none" | "metadata" | "auto";
  poster?: string;
  sources?: Source[];
  tracks?: TextTrackOptions[];
  plugins?: Record<string, any>;
  techOrder?: string[];
  html5?: Html5Options;
  playbackRates?: number[];
  language?: string;
  languages?: Record<string, any>;
  notSupportedMessage?: string;
  [key: string]: any;
}

interface Source {
  src: string;
  type: string;
  label?: string;
}

interface Html5Options {
  nativeTextTracks?: boolean;
  nativeAudioTracks?: boolean;
  nativeVideoTracks?: boolean;
  preloadTextTracks?: boolean;
  [key: string]: any;
}

interface MediaError {
  code: number;
  message: string;
  status?: number;
}

Install with Tessl CLI

npx tessl i tessl/npm-video-js

docs

components.md

events.md

index.md

player.md

plugins.md

tech.md

tracks.md

utilities.md

tile.json