Providers

VideoProvider

The VideoProvider is a component that manages the state of the video player and makes it available to all its children.

Usage

To use the VideoProvider, you need to wrap your component with it. This is usually done in the component that contains the video player.

import { VideoProvider } from 'react-native-video-toolkit';

export const VideoPlayerComponent = () => <VideoProvider>{/* Your video player content */}</VideoProvider>;

Props

PropTypeDefaultDescription
configPartial<VideoPlayerConfig>{}The configuration for the video player.
themePartial<Theme>{}The theme for the video player.
componentsPartial<VideoComponents>{}Replacements for the sheet, sliders, spinner and press feedback the player renders. See Custom Components.
portalHoststring–Name of a VideoPortalHost to open the settings sheet in. When left out, the provider renders its own host after its children.
childrenReactNoderequiredThe children to render.

VideoPortalHost

The settings sheet opens in a portal host that VideoProvider renders after its children. If the provider sits inside a screen (for example one tab of a tab navigator), the sheet is drawn inside that screen, so the navigator's tab bar or header can end up on top of it.

To open the sheet above your navigation instead, render a VideoPortalHost at the app root, after the navigator, and pass its name to portalHost. One host can serve every player in the app.

import { Slot } from 'expo-router';
import { DefaultLayout, VideoPlayer, VideoPortalHost, VideoProvider } from 'react-native-video-toolkit';

// App root, e.g. app/_layout.tsx
export default function RootLayout() {
  return (
    <>
      <Slot />
      <VideoPortalHost name="app" />
    </>
  );
}

// Any screen
export const PlayerScreen = () => (
  <VideoProvider portalHost="app">
    <VideoPlayer source={{ uri: 'https://example.com/video.mp4' }}>
      <DefaultLayout />
    </VideoPlayer>
  </VideoProvider>
);

This applies to the default sheet. A custom Sheet renders wherever its library puts it; for @gorhom/bottom-sheet, place BottomSheetModalProvider at the app root for the same effect.

State

The VideoProvider manages the following state. Read it with useVideoSelector(), which re-renders only when the part you select changes, or useVideo(), which re-renders on every change:

StateTypeDescription
isPlayingbooleanWhether the video is playing.
durationnumberThe duration of the video in seconds.
bufferingbooleanWhether the video is buffering.
mutedbooleanWhether the video is muted.
volumenumberThe volume of the video.
playbackRatenumberThe playback rate of the video.
fullscreenbooleanWhether the video is in fullscreen mode.
errorstring nullAn error message, if any.
configVideoPlayerConfigThe configuration for the video player.
themeThemeThe theme for the video player.
videoRefReact.MutableRefObject<VideoRef | null>A ref to the video component. It's set from the first render, and its current is null until the player mounts.
controlsVisiblebooleantrueWhether the controls are currently visible.
videoWrapperLayoutLayoutRectangleThe layout of the view wrapping the video component.
videoLayoutLayoutRectangleThe layout of the video component.
dimensions{ width: number; height: number }The dimensions of the screen.

The playback position (currentTime and playableDuration) isn't part of the state. Read it with useProgress(): it changes on every progress event, and keeping it out of the state means only the components that call useProgress() re-render.

Actions

The VideoProvider handles the following actions:

ActionPayloadDescription
INITIALIZE{ theme?: Partial<Theme>; config?: Partial<VideoPlayerConfig> }Initializes the provider with a theme and config.
SET_THEMEPartial<Theme>Sets the theme.
SET_CONTROLS_VISIBLEbooleanSets the visible state of the controls.
SET_VIDEO_REFReact.RefObject<any>Sets a ref to the video component.
SHOW_CONTROLSShows the controls.
HIDE_CONTROLSHides the controls.
SEEKnumberSeeks the video to a specific time.
TOGGLE_PLAY_PAUSEToggles the play/pause state of the video.
SET_VOLUMEnumberSets the volume of the video.
TOGGLE_MUTEToggles the mute state of the video.
TOGGLE_FULLSCREENToggles the fullscreen mode.
SET_PLAYINGbooleanSets the playing state of the video.
SET_DURATIONnumberSets the duration of the video.
SET_BUFFERINGbooleanSets the buffering state of the video.
SET_ERRORstring nullSets an error message.
SET_VIDEO_LAYOUTLayoutRectangleSets the layout of the video component.
SET_DIMENSIONS{ width: number; height: number }Sets the dimensions of the screen.

useVideo

The useVideo hook provides access to the video state and dispatch function.

Returns

ValueTypeDescription
stateVideoProviderStateThe video state.
dispatchReact.Dispatch<Action>The dispatch function.

On this page