twitch-video
Video component that plays Twitch videos and live channels through the Twitch embed player
Video component that plays Twitch videos and live channels through the Twitch embed player. Twitch’s own chrome stays hidden by default, so it drops into a player skin like any other media component; set controls to use Twitch’s UI instead.
Load a source
src takes a video URL (twitch.tv/videos/<id>) or a channel URL (twitch.tv/<channel>), with or without the www. and go. hosts. A channel URL plays the channel’s live stream. Clips (clips.twitch.tv) are a different embed and aren’t supported.
<TwitchVideo src="https://www.twitch.tv/videos/106400740" /><twitch-video src="https://www.twitch.tv/videos/106400740"></twitch-video>Live channels
A channel embed behaves like a live media component:
durationreportsInfinitywhile the stream is live.- Seeking is unavailable: the embed exposes no DVR window.
- The stream going away and coming back dispatch
offlineandonlineevents. loopnever repeats a channel; a live stream doesn’t end.
Parent hostnames
Twitch checks the embedding page’s ancestors against a parent allowlist and won’t play unless the current page is on it. The element always includes your page’s own hostname, so a plain embed needs no setup. When your player is itself framed by other hostnames, name each of them under engine.twitch.parent:
<TwitchVideo
source={{
src: 'https://www.twitch.tv/videos/106400740',
engine: { twitch: { parent: ['embed.example.com'] } },
}}
/>const video = document.querySelector('twitch-video');
video.source = {
src: 'https://www.twitch.tv/videos/106400740',
engine: { twitch: { parent: ['embed.example.com'] } },
};Behavior
- Volume and mute both work, like a native
<video>. playbackRateis reported but never applied: the embed has no rate command.looprestarts a finished video from the top; the embed has no loop parameter.controlsis read when the embed is built; changing it later doesn’t take effect, since rebuilding the iframe would lose the playback session.- Fullscreen targets the iframe, so Twitch’s own chrome shows in fullscreen.
Examples
Basic Usage
import { TwitchVideo } from '@videojs/react/media/twitch-video';
export default function BasicUsage() {
return (
<div className="twitch-video">
<TwitchVideo src="https://www.twitch.tv/videos/106400740" controls />
</div>
);
}
.twitch-video {
width: 100%;
aspect-ratio: 16 / 9;
}
<twitch-video
class="twitch-video"
src="https://www.twitch.tv/videos/106400740"
controls
></twitch-video>
.twitch-video {
width: 100%;
aspect-ratio: 16 / 9;
}
import '@videojs/html/media/twitch-video';
API Reference
Attributes
These attributes configure the embedded media adapter:
| Attribute | Type | Default | Details |
|---|---|---|---|
autoplay | boolean | — | |
controls | boolean | — | |
loop | boolean | — | |
muted | boolean | — | |
playsinline | boolean | — | |
poster | string | — | |
preload | MediaPreloadType | — | |
src | string | — |
Properties
| Property | Type | Default | Details |
|---|---|---|---|
autoplay | boolean | — | |
buffered | TimeRangeLike | — | |
| |||
controls | boolean | — | |
currentSrc | string | — | |
| |||
currentTime | number | — | |
defaultMuted | boolean | — | |
duration | number | — | |
| |||
ended | boolean | — | |
| |||
engine | Window | null | — | |
| |||
error | MediaError | null | — | |
| |||
isFullscreen | boolean | — | |
| |||
loop | boolean | — | |
muted | boolean | — | |
paused | boolean | — | |
| |||
playbackRate | number | — | |
playsInline | boolean | — | |
poster | string | — | |
preload | MediaPreloadType | — | |
readyState | number | — | |
| |||
seekable | TimeRangeLike | — | |
| |||
seeking | boolean | — | |
| |||
source | TwitchSource | null | — | |
| |||
src | string | — | |
textTracks | TextTrackListLike | — | |
| |||
volume | number | — | |
Engine options
source.engine.twitch
Pass Twitch embed parameters under source.engine.twitch, spelled exactly as Twitch spells them, plus anything Twitch adds next. Media Sources covers how engine options fit into a structured source.
controls, autoplay, and muted come from the props of the same name, and the video or channel comes from src, so none of those have an engine.twitch spelling.
| Option | Type | Details |
|---|---|---|
collection | string | |
| ||
parent | string | readonly string[] | |
| ||
referrerPolicy | ReferrerPolicy | |
| ||
time | string | |
| ||
Methods
Supports these media methods: exitFullscreenloadpauseplayrequestFullscreen
Events
Implements these standard media events through the embedded player: durationchangeemptiedendederrorloadedmetadataloadstartplayingprogressseekedseekingtimeupdatevolumechangewaiting
Also emits these Video.js-specific events:
| Event | Description |
|---|---|
loadcomplete | |
sourcechange | Fired when `source` changes, either directly or by resolving a new `src`. Read `source` for the new value. |