### Install Project Dependencies
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/CONTRIBUTING.md
Installs all necessary project dependencies and sets up Husky commit hooks. This command should be run after cloning the forked repository.
```bash
npm install
```
--------------------------------
### Install React Hover Video Player
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Installs the react-hover-video-player package using npm. This is the first step to using the library in a React project.
```bash
npm install react-hover-video-player
```
--------------------------------
### Run Documentation Development Server
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/CONTRIBUTING.md
Starts a local development server to preview the documentation site. The site is built using VuePress and can be accessed at http://localhost:8080.
```bash
npm run docs:dev
```
--------------------------------
### React Hover Video Player loadingOverlay Prop Example
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Demonstrates the `loadingOverlay` prop, which displays content during video buffering after playback initiation. This overlay appears above the `pausedOverlay` and provides buffering feedback, especially for slower connections. Includes a `loadingStateTimeout` prop example.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function VideoWithLoadingState() {
return (
}
loadingOverlay={
}
loadingStateTimeout={300}
/>
);
}
```
--------------------------------
### Run Development Playground Server
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/CONTRIBUTING.md
Starts a local development server to test changes in a live demo environment. The playground is served from the `dev/index.tsx` file at http://localhost:8080.
```bash
npm run dev
```
--------------------------------
### React Hover Video Player pausedOverlay Prop Example
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Shows how to use the `pausedOverlay` prop to display content, such as a thumbnail image, when the video is paused or loading. This overlay fades out when playback starts and reappears when paused.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function VideoWithThumbnail() {
return (
}
/>
);
}
```
--------------------------------
### React Hover Video Player videoSrc Prop Examples
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Illustrates how to use the `videoSrc` prop, which accepts either a single video URL string or React nodes with multiple `` elements for format fallbacks. It's recommended to order multiple sources by ascending file size.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
// Single source
function SingleSource() {
return (
);
}
// Multiple sources with format fallbacks
function MultipleSources() {
return (
>
}
/>
);
}
```
--------------------------------
### Handle Hover Start Event in React Hover Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The `onHoverStart` prop accepts a callback function that is executed when the user begins hovering over or touching the player's designated hover target.
```jsx
{
console.log('User just moused over or touched hover target.');
console.log('The video will now attempt to play.');
}}
/>
```
--------------------------------
### Delay Video Playback Start with React Hover Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The `playbackStartDelay` prop allows you to specify a delay in milliseconds before the video starts loading after a user begins hovering. This is useful for reducing server load when self-hosting many videos. It's recommended to use a loading overlay with this prop to provide visual feedback during the delay.
```jsx
```
--------------------------------
### Set Playback Range Start for HoverVideoPlayer
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Configure the starting point for video playback using the `playbackRangeStart` prop. This prop accepts a number in seconds, specifying when the video should begin playing. If not provided, playback starts from the video's beginning. This is useful for previewing specific sections of longer videos.
```jsx
```
--------------------------------
### React Hover Video Player hoverOverlay Prop Example
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Illustrates the `hoverOverlay` prop, which renders content on top of the playing video during hover. This is useful for displaying supplementary information like titles or calls-to-action while the video plays in the background.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function VideoWithHoverInfo() {
return (
}
hoverOverlay={
Video Title
Click to watch the full video
}
/>
);
}
```
--------------------------------
### Access Video Element with videoRef Prop in React
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Illustrates how to use the `videoRef` prop to get a React ref to the underlying video element. This allows direct manipulation, such as adjusting playback rate or adding custom event listeners.
```jsx
import { useRef, useEffect } from 'react';
import HoverVideoPlayer from 'react-hover-video-player';
function SlowMotionVideo() {
const videoRef = useRef(null);
useEffect(() => {
if (videoRef.current) {
// Set video to play at half speed
videoRef.current.playbackRate = 0.5;
}
}, []);
return (
}
/>
);
}
```
--------------------------------
### Show Loading Overlay Content
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The loadingOverlay prop enables you to display custom content when the video takes too long to start playing after a user attempts to play it. This overlay appears on top of the pausedOverlay and is useful for providing feedback to users with slower internet connections. The duration before this overlay appears can be controlled by the loadingStateTimeout prop.
```jsx
Loading...}
/>
```
--------------------------------
### Set Video Player Sizing Mode to Container
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The sizingMode prop controls how the video player's content is sized. Setting it to 'container' makes the video and overlays expand to fill the component's outer div. This example demonstrates using 'container' mode with custom styling to maintain a 16:9 aspect ratio.
```jsx
```
--------------------------------
### Disable Default Event Handling in React Hover Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The `disableDefaultEventHandling` prop, when set to true, stops the player from automatically playing on mouse enter/touch start and pausing on mouse leave/touch start outside the player. This is useful for custom event implementations.
```jsx
const [isVideoPlaying, setIsVideoPlaying] = useState(false);
...
setIsVideoPlaying(!isVideoPlaying)}
>
```
--------------------------------
### Set Loading State Timeout for Hover Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Determines the delay in milliseconds before the loading state is displayed if the video doesn't start playing immediately. This prevents premature loading indicators for quick-starting videos.
```jsx
Loading...}
// We should only show the loading state if the video takes
// more than 1 full second to start after attempting to play
loadingStateTimeout={1000}
/>
```
--------------------------------
### Display Paused Overlay Content
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The pausedOverlay prop allows you to render custom content over the video when it is paused or loading. This content fades out when the video starts playing. A common use case is displaying a thumbnail image, ensuring it covers the video's dimensions.
```jsx
}
/>
```
--------------------------------
### Unload Video When Paused with React Hover Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The `unloadVideoOnPaused` prop, when set to true, ensures that video assets are completely unloaded when the video is not playing. This helps mitigate performance issues caused by multiple large videos loading in the background. Note that this may slightly increase video start times on repeat plays and requires a paused overlay for a seamless user experience.
```jsx
```
--------------------------------
### Build Project for Production
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/CONTRIBUTING.md
Compiles and bundles the project for production deployment. This command is part of the release process.
```bash
npm run build:prod
```
--------------------------------
### Handle Video Events with onHoverStart and onHoverEnd Callbacks in React
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Demonstrates using `onHoverStart` and `onHoverEnd` callbacks to react to user hover events on the player. These are useful for analytics or coordinating UI changes with video playback.
```jsx
import { useState } from 'react';
import HoverVideoPlayer from 'react-hover-video-player';
function VideoWithAnalytics() {
const [hoverCount, setHoverCount] = useState(0);
return (
);
}
```
--------------------------------
### Provide Multiple Video Sources
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Illustrates how to provide multiple video sources for the HoverVideoPlayer component using `` elements within a React fragment. It's recommended to order sources by ascending file size.
```jsx
>
)
/>
```
--------------------------------
### onHoverStart
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Callback function fired when the user hovers over the player's hover target.
```APIDOC
## onHoverStart
### Description
Accepts a callback function which will be fired when the user hovers on the player's [hover target](#hovertarget).
### Type
`function`
### Default
`null`
### Request Example
```jsx
{
console.log('User just moused over or touched hover target.');
console.log('The video will now attempt to play.');
}}
/>
```
```
--------------------------------
### Basic Usage of HoverVideoPlayer Component
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Demonstrates the basic implementation of the HoverVideoPlayer component in React. It shows how to provide the video source and optional loading and paused state overlays.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function MyComponent() {
return (
}
loadingOverlay={
}
/>
);
}
```
--------------------------------
### Overlay Transition and Loading State Props
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Configure the transition duration for overlays and the timeout for loading states.
```APIDOC
## overlayTransitionDuration
### Description
Accepts the number of milliseconds for the paused and loading overlays to fade in and out as the player's state changes.
### Method
N/A (Prop)
### Endpoint
N/A (Prop)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
- **overlayTransitionDuration** (number) - Required - The duration in milliseconds for overlay transitions.
### Request Example
```jsx
Paused!}
overlayTransitionDuration={500}
/>
```
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
---
## loadingStateTimeout
### Description
Accepts the number of milliseconds the player should wait before showing a loading state if the video is not able to play immediately.
### Method
N/A (Prop)
### Endpoint
N/A (Prop)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
- **loadingStateTimeout** (number) - Required - The timeout in milliseconds before showing the loading state.
### Request Example
```jsx
Loading...}
loadingStateTimeout={1000}
/>
```
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
```
--------------------------------
### Provide Single Video Source
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Shows how to specify a single video source for the HoverVideoPlayer component using a string URL.
```jsx
```
--------------------------------
### Customizing Video Player Styles with Props
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Demonstrates how to apply custom styles to the container, video element, and overlay wrappers of the HoverVideoPlayer component using className and style props. This allows for detailed visual customization of the player's appearance.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function FullyStyledVideo() {
return (
}
// Loading overlay wrapper styling
loadingOverlayWrapperClassName="loading-wrapper"
loadingOverlayWrapperStyle={{ backgroundColor: 'rgba(0,0,0,0.5)' }}
loadingOverlay={
}
// Transition timing
overlayTransitionDuration={500}
loadingStateTimeout={300}
/>
);
}
```
--------------------------------
### Basic React Hover Video Player Usage
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Demonstrates the simplest implementation of the HoverVideoPlayer component. It requires only the video source URL and automatically handles hover, playback, and pause states.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function VideoThumbnail() {
return (
);
}
```
--------------------------------
### Optimize Video Performance with Unload, Delay, and Preload Props in React
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
Shows how to optimize video performance using `unloadVideoOnPaused`, `playbackStartDelay`, and `preload` props. These props help reduce memory usage, server load, and control data loading before playback.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function OptimizedVideoGallery() {
const videos = [
{ src: 'video1.mp4', thumb: 'thumb1.jpg' },
{ src: 'video2.mp4', thumb: 'thumb2.jpg' },
{ src: 'video3.mp4', thumb: 'thumb3.jpg' },
];
return (
);
}
```
--------------------------------
### Convert Video Recording to GIF with ffmpeg
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/CONTRIBUTING.md
Converts a video recording to a GIF file with optimized frame rate, scaling, and color palette. This command is recommended for creating documentation GIFs.
```bash
ffmpeg -i path/to/original-recording.mp4 -vf "fps=10,scale=1024:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output/demo.gif
```
--------------------------------
### Control Sizing with sizingMode Prop
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
The `sizingMode` prop dictates how the player's content is scaled. Available options include 'video' (default), 'overlay', 'container', and 'manual', offering flexibility in how the video and its overlays adapt to different layouts.
```jsx
// Container-based sizing with fixed aspect ratio
function FixedAspectRatioVideo() {
return (
}
/>
);
}
// Overlay-based sizing
function OverlaySizedVideo() {
return (
}
/>
);
}
```
--------------------------------
### videoRef
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Exposes a ref to the video element, allowing direct access for advanced customization.
```APIDOC
## videoRef
### Description
Can be used to expose a ref to the video element rendered by HoverVideoPlayer. This is useful if you need to directly access the video element to extend its behavior in some way, but beware that any changes you make could produce unexpected behavior from the component.
### Type
`React.Ref`
### Default
`null`
### Request Example
```jsx
const hoverVideoRef = useRef();
useEffect(() => {
const videoElement = hoverVideoRef.current;
videoElement.playbackRate = 2;
}, []);
return ;
```
```
--------------------------------
### volume
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Sets the volume for the video's audio, ranging from 0 to 1. Requires `muted` to be `false`.
```APIDOC
## volume
### Description
Accepts a number on a scale from 0-1 for the volume that the video's audio should play at.
Note that this will only work if the [muted](#muted) prop is also set to `false`.
### Type
`number`
### Default
`1`
### Request Example
```jsx
```
```
--------------------------------
### Run All Automated Tests
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/CONTRIBUTING.md
Executes all automated tests using Playwright. Ensure all tests pass before submitting changes. This command can also accept a specific test file name as an argument to run only that file.
```bash
npm run test
```
```bash
npm run test -- videoSrc.spec.ts
```
--------------------------------
### Hover Overlay Prop
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Define custom content to be displayed over the video during hover or focus states.
```APIDOC
## hoverOverlay
### Description
An optional prop that accepts any renderable content to be displayed over the video while the player is active from a hover/touch event or when the `focused` prop is `true`. This overlay takes the highest ordering priority.
### Method
N/A (Prop)
### Endpoint
N/A (Prop)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
- **hoverOverlay** (node) - Optional - Renderable content for the hover overlay.
### Request Example
```jsx
Video Title
Here is a short description of the video.
}
/>
```
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
```
--------------------------------
### Display Custom Content with Hover Overlay in Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Allows rendering custom content on top of the video when the player is active due to hover, touch, or focus. This overlay has the highest z-index and can be used to display titles, descriptions, or interactive elements.
```jsx
Video Title
Here is a short description of the video. You can still see the video
playing underneath this overlay.
Click here to read more
}
/>
```
--------------------------------
### Set Overlay Transition Duration for Hover Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Configures the time in milliseconds for the paused and loading overlays to fade in and out. This ensures a seamless user experience as the player's state changes.
```jsx
Paused!}
// It should take 500ms for the pausedOverlay to fade out when
// the video plays and fade back in when the video pauses
overlayTransitionDuration={500}
/>
```
--------------------------------
### loop
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Toggles whether the video should loop when it reaches the end.
```APIDOC
## loop
### Description
Accepts a boolean value which toggles whether or not the video should loop when it reaches the end.
### Type
`boolean`
### Default
`true`
### Request Example
```jsx
```
```
--------------------------------
### restartOnPaused
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Toggles whether the video should restart from the beginning when paused.
```APIDOC
## restartOnPaused
### Description
Accepts a boolean value which will toggle whether the video should be reset to the start every time it is paused or resume from the previous time it was at.
### Type
`boolean`
### Default
`false`
### Request Example
```jsx
```
```
--------------------------------
### Set Video Preload to Metadata
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The preload prop corresponds to the HTML Video element's preload attribute, determining how much data is loaded before playback. Setting it to 'metadata' ensures only the video's metadata (dimensions, duration) is loaded initially. This is useful for performance but may require a paused overlay in Safari.
```jsx
```
--------------------------------
### Programmatic Video Control with focused Prop
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
The `focused` prop offers direct control over video playback, overriding the default hover behavior. Setting it to `true` forces playback, while `false` reverts to standard hover interactions.
```jsx
import { useState } from 'react';
import HoverVideoPlayer from 'react-hover-video-player';
function ControlledVideoPlayer() {
const [isPlaying, setIsPlaying] = useState(false);
return (
}
/>
);
}
```
--------------------------------
### Apply Custom Styling to HoverVideoPlayer
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Customize the appearance of the `HoverVideoPlayer` component using various props that accept class names and style objects. These props allow targeted styling for the outer container, overlay wrappers, and the video element itself, providing flexibility in UI integration.
```jsx
```
--------------------------------
### Define Playback Segment with playbackRange Props
Source: https://context7.com/gyanreyer/react-hover-video-player/llms.txt
The `playbackRangeStart` and `playbackRangeEnd` props allow you to specify a precise segment of the video for playback, measured in seconds. This is ideal for showcasing specific parts of longer videos without altering the original file.
```jsx
import HoverVideoPlayer from 'react-hover-video-player';
function VideoPreviewClip() {
return (
}
/>
);
}
```
--------------------------------
### Define Hover Target Element for Video Player
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
Specifies the DOM element, a function returning a DOM element, or a React ref that will trigger the video playback on hover or touch. If not provided, the component's container acts as the target.
```jsx
// Passing a function that returns a DOM node
document.getElementById("hover-target")}
/>
...
// Using a React ref
const wrapperLinkRef = useRef();
...
// Passing a DOM node
// PLEASE BEWARE THAT THIS CAN BE UNSAFE: Only do this if you are confident that the element
// will always already exist on the DOM before this component is rendered.
```
--------------------------------
### Implement Closed Captions with videoCaptions
Source: https://github.com/gyanreyer/react-hover-video-player/blob/main/docs/README.md
The videoCaptions prop allows you to add closed captions to your video player. It accepts a React node containing one or more