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.
childrenReactNoderequiredThe children to render.

State

The VideoProvider manages the following state:

StateTypeDescription
isPlayingbooleanWhether the video is playing.
currentTimenumberThe current time of the video in seconds.
playableDurationnumberThe playable duration of the video in seconds.
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.RefObject<any>nullA ref to the video component.
controlsVisiblebooleantrueWhether the controls are currently visible.
hideTimeoutRefNodeJS.TimeoutnullA timeout ref for hiding the controls.
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.

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_CURRENT_TIMEnumberSets the current time of the video.
SET_PLAYABLE_DURATIONnumberSets the playable duration 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_HIDE_TIMEOUTNodeJS.Timeout nullSets a timeout for hiding the controls.
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.