@zezosoft/react-player v0.0.3
@zezosoft/react-player š¬
A powerful and flexible React video player by Zezosoft, supporting HLS, MP4, preview thumbnails, tracking, and advanced playback controls.
š Features
ā
Supports HLS, MP4
ā
Preview Thumbnails on Hover
ā
Event Tracking (Views, Watch Time, etc.)
ā
Customizable Player Size & Controls
ā
Time-Stamped Labels for Video Chapters
š¦ Installation
Install the package using npm or yarn:
npm install @zezosoft/react-player
š ļø Basic Usage
Import and use the VideoPlayer
component in your React project:
import { useCallback, useRef } from "react";
import { VideoPlayer } from "@zezosoft/react-player";
function App() {
const previewImage = useRef("");
// Generate dynamic preview images based on hover time
const updatePreviewImage = (hoverTime: number) => {
const url = `https://fakeimg.pl/720x405?text=${hoverTime}`;
const image = document.createElement("img");
image.src = url;
image.onload = () => {
previewImage.current = url;
};
};
const handleGettingPreview = useCallback((hoverTime: number) => {
updatePreviewImage(hoverTime);
return previewImage.current;
}, []);
return (
<div className="w-[720px]">
<VideoPlayer
trackPoster="https://i.ytimg.com/vi/VAUfyxw-Yvk/maxresdefault.jpg"
trackSrc="https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8"
trackTitle="Mehmaan"
width="720px"
height="405px"
timeCodes={[
{ fromMs: 0, description: "Introduction" },
{ fromMs: 130000, description: "Exciting Scene" },
{ fromMs: 270000, description: "Climax" },
]}
getPreviewScreenUrl={handleGettingPreview}
tracking={{
onViewed: () => console.log("Video Viewed"),
onWatchTimeUpdated: (e) => console.log("Watch Time Updated", e),
}}
/>
</div>
);
}
export default App;
šØ Props Reference
Prop Name | Type | Default | Description |
---|---|---|---|
trackPoster | string | "" | URL of the video poster image. |
trackSrc | string | "" | Video source URL (MP4, HLS, etc.). |
trackTitle | string | "" | Title of the video. |
isTrailer | boolean | false | Specifies if the video is a trailer. |
width | string | "100%" | Width of the video player. |
height | string | "auto" | Height of the video player. |
timeCodes | Array<{ fromMs: number, description: string }> | [] | List of time-based markers with descriptions. |
getPreviewScreenUrl | (timeMs: number) => string | null | Function to generate preview screen URLs based on time. |
tracking | object | {} | Tracking event callbacks. |
š¢ Tracking Events
Event Name | Description |
---|---|
onViewed | Triggered when the video is viewed. |
onWatchTimeUpdated | Triggered when the watch time is updated. |
Example usage:
tracking={{
onViewed: () => console.log("Video viewed"),
onWatchTimeUpdated: (e) => console.log("Current watch time:", e),
}}
šØ Customization & Styling
š¹ Change Player Dimensions
Modify width
and height
:
<VideoPlayer width="800px" height="450px" />
š¹ Custom Preview Thumbnails
Dynamically generate preview images:
const getPreviewImage = (hoverTime) =>
`https://fakeimg.pl/720x405?text=${hoverTime}`;
<VideoPlayer getPreviewScreenUrl={getPreviewImage} />;
š¹ Time-Stamps for Video Sections
Mark important video sections:
<VideoPlayer
timeCodes={[
{ fromMs: 0, description: "Introduction" },
{ fromMs: 120000, description: "Key Scene" },
]}
/>
ā Troubleshooting
ā Video not playing?
- Check if the
trackSrc
URL is correct. - Ensure the video format (MP4, HLS) is supported.
- If using HLS, ensure you're serving files correctly (CORS issues may block playback).
ā Preview thumbnails not loading?
- Confirm
getPreviewScreenUrl
is returning a valid image URL. - Use the browser console (F12) to check errors.
ā Player not responsive?
- Make sure you're setting
width="100%"
for fluid responsiveness - Wrap the player inside a
div
with CSS styles
š Related Links
š License
Licensed under the MIT License. Developed by Zezosoft. š
š Credits
This project includes modifications of the seek bar functionality inspired by react-video-seek-slider
.