Skip to content

ReferenceMedia

Video

Native video playback that can provide media to a Video.js player

Import

Import Video from the video preset:

import { Video } from '@videojs/react/video';

Anatomy

<Video>
  <source />
  <track />
</Video>

Use with a player

Place Video anywhere inside a VideoPlayer, or inside another Video.js Player configured for video. It becomes that player’s media provider automatically. Outside a player, Video behaves as a standalone native <video>.

Native behavior

Video.js does not replace the native video API. Use src for one URL or add child <source> elements when the browser should choose between candidates. See Media sources when you need an HLS, DASH, Mux, or other playback adapter.

Add native <track> elements for captions, subtitles, chapters, descriptions, or metadata.

Video forwards native attributes, event handlers, and children to the underlying <video>. See Refs for what ref and mediaRef receive.

See MDN for the complete <video> element, HTMLVideoElement, and shared HTMLMediaElement APIs.

Examples

Basic Usage

This native video uses a child source, captions track, and browser controls while also providing media to the surrounding Video.js player.

import { Container } from '@videojs/react';
import { Video, VideoPlayer } from '@videojs/react/video';

import './BasicUsage.css';

export default function BasicUsage() {
  return (
    <VideoPlayer>
      <Container className="react-video-basic">
        <Video className="react-video-basic__media" controls playsInline preload="metadata">
          <source src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" type="video/mp4" />
          <track kind="captions" src="/docs/demos/captions-button/captions.vtt" srcLang="en" label="English" />
        </Video>
      </Container>
    </VideoPlayer>
  );
}

API Reference

Props

Accepts the standard React props for a native <video>: autoPlaycontrolscontrolsListcrossOrigindisablePictureInPicturedisableRemotePlaybackheightloopmutedplaysInlineposterpreloadsrcwidth

Video also accepts children and common element props such as className and style, plus these Video.js-specific props:

PropTypeDescription
fallbackReactNodeContent rendered inside the <video> after children, which only browsers without media element support show. It isn’t shown when playback fails. Defaults to a “Video player not working?” link to https://videojs.org/help. Pass null to render nothing.
mediaRefRef<HTMLVideoElement>Receives the rendered HTMLVideoElement. See Refs.

Refs

ref

Forwards to the rendered <video>, an HTMLVideoElement with its complete native property and method API.

const ref = useRef<HTMLVideoElement>(null);

<Video ref={ref} />

mediaRef

Receives the same HTMLVideoElement as ref. Adapter-backed components such as HlsJsVideo and YouTubeVideo hand their playback adapter to mediaRef instead, so code that works with several media components can read the playback object from one prop.

const mediaRef = useRef<HTMLVideoElement>(null);

<Video mediaRef={mediaRef} />

Events

Accepts the standard React media event props: onAbortonCanPlayonCanPlayThroughonDurationChangeonEmptiedonEncryptedonEndedonErroronLoadedDataonLoadedMetadataonLoadStartonPauseonPlayonPlayingonProgressonRateChangeonResizeonSeekedonSeekingonStalledonSuspendonTimeUpdateonVolumeChangeonWaiting

The native enterpictureinpicture, leavepictureinpicture, and waitingforkey events have no React prop. Attach a listener through the ref with addEventListener.