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],
});
import { createPlayer, source } from '@videojs/html';
const { ProviderMixin, PlayerController, context } = createPlayer({
features: [source],
});
State
The current media source URL, or null if no source has been loaded.
Whether enough data has been loaded to begin playback.
Actions
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>;
}
import { createPlayer, MediaElement, selectSource } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';
const { PlayerController, context } = createPlayer({ features: videoFeatures });
class SourceInfo extends MediaElement {
readonly #source = new PlayerController(this, context, selectSource);
}