Primer

Video player

Use the video player component to enable playback of self-hosted videos
import {VideoPlayer} from '@primer/react-brand'

Examples

Default

With poster

Without branding

With visually hidden title

With some hidden controls

Hide controls when paused

Minimal

Custom play icon

Controlling programmatically

The VideoPlayer component exposes a useVideo hook that can be used to control the video programmatically. To use the hook, the VideoPlayer component must be wrapped in a VideoPlayer.Provider component.

Full documentation for the useVideo hook can be found below.

useVideo Context

The useVideo context provides a comprehensive API for managing video playback, volume, closed captioning, and fullscreen mode.

The context can be accessed by using the useVideo hook in any component that is a child of VideoPlayer.Provider.

Below is a detailed description of each property and method available in the useVideo context.

NameTypeDescription
refRefObject<HTMLVideoElement>A reference to the video element.
isPlayingbooleanIndicates if the video is currently playing.
volumenumberThe current volume of the video, ranging from 0 to 1.
isMutedbooleanIndicates if the video is currently muted.
volumeBeforeMutenumberThe volume of the video before it was muted, allowing for easy unmuting to the previous level.
durationnumberThe total duration of the video in seconds.
ccEnabledbooleanIndicates if closed captions are enabled.
isFullScreenbooleanIndicates if the video is currently in fullscreen mode.
play() => voidPlays the video.
pause() => voidPauses the video.
togglePlaying() => voidToggles between playing and pausing the video.
setVolume(volumeValOrFn: SetStateAction<number>) => voidSets the volume of the video.
mute() => voidMutes the video.
unmute() => voidUnmutes the video.
toggleMute() => voidToggles between muting and unmuting the video.
setDuration(duration: number) => voidSets the duration of the video.
seekToPercent(percent: number) => voidSeeks the video to a specific percentage of its duration.
seek(secondsValOrFn: SetStateAction<number>) => voidSeeks the video to an absolute time, or to a relative time if passed a function.
enableCC() => voidEnables closed captions.
disableCC() => voidDisables closed captions.
toggleCC() => voidToggles closed captions on and off.
enterFullScreen() => voidEnters fullscreen mode.
exitFullScreen() => voidExits fullscreen mode.
toggleFullScreen() => voidToggles between entering and exiting fullscreen mode.

Component props

VideoPlayer Required

VideoPlayer provides a React alternative to the native HTML <video />.

NameTypeDefaultRequiredDescription
childrenReact.ReactNode, React.ReactNode[]trueTakes <VideoPlayer.Source> and <VideoPlayer.Track> elements
titlestringtrueSets the title of the video
visuallyHiddenTitlebooleanfalseVisually hides the title of the video in the upper-left corner
showBrandingbooleantruefalseDisplays GitHub branding next to video title
posterstringfalseSets an image as the starting frame for the video element
classNamestringfalseSets a custom class on the <video> element
showControlsWhenPausedbooleantruefalseShow the video controls when paused
showPlayPauseButtonbooleantruefalseShow the play button control
showSeekControlbooleantruefalseShow the seek control
showCCButtonbooleantruefalseShow the closed caption toggle control
showMuteButtonbooleantruefalseShow the mute button control
showVolumeControlbooleantruefalseShow the volume control
showFullScreenButtonbooleantruefalseShow the full screen button control

The component API supports all standard HTML attribute props, while providing some additional behavior as described above.

VideoPlayer.Source Required

VideoPlayer.Source provides a React alternative to the native HTML <source />. The component API supports all standard HTML attribute props.

VideoPlayer.Track Required

VideoPlayer.Track provides a React alternative to the native HTML <track />.

NameTypeDefaultRequiredDescription
kind'subtitles', 'captions', 'descriptions', 'chapters', 'metadata''captions'falseSets how the text track is meant to be used

The component API supports all standard HTML attribute props, while providing some additional behavior as described above.

VideoPlayer.Provider

VideoPlayer.Provider can be used in conjunction with the useVideo hook to enable programmatic access to features such as video playback, volume, closed captioning, and fullscreen mode.