0.0.3 • Published 4 months ago

@zezosoft/react-player v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@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 NameTypeDefaultDescription
trackPosterstring""URL of the video poster image.
trackSrcstring""Video source URL (MP4, HLS, etc.).
trackTitlestring""Title of the video.
isTrailerbooleanfalseSpecifies if the video is a trailer.
widthstring"100%"Width of the video player.
heightstring"auto"Height of the video player.
timeCodesArray<{ fromMs: number, description: string }>[]List of time-based markers with descriptions.
getPreviewScreenUrl(timeMs: number) => stringnullFunction to generate preview screen URLs based on time.
trackingobject{}Tracking event callbacks.

šŸ“¢ Tracking Events

Event NameDescription
onViewedTriggered when the video is viewed.
onWatchTimeUpdatedTriggered 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.


🌟 Enjoy seamless video playback with @zezosoft/react-player! šŸŽ„