Skip to main content
Tracks the current media source URL and readiness.

Import

import { source, selectSource } from '@videojs/react';
// or
import { source, selectSource } from '@videojs/html';

Usage

import { createPlayer, source } from '@videojs/react';

const Player = createPlayer({
  features: [source],
});

State

source
string | null
The current media source URL, or null if no source has been loaded.
canPlay
boolean
Whether enough data has been loaded to begin playback.

Actions

loadSource(src)
(src: string) => void
Load a new media source by URL.

Selector

Use selectSource to subscribe to only the source slice of state. Returns undefined if the source feature is not configured.
import { selectSource, usePlayer } from '@videojs/react';

function SourceInfo() {
  const source = usePlayer(selectSource);
  if (!source) return null;

  return <span>{source.source ?? 'No source'}</span>;
}

Build docs developers (and LLMs) love