1.0.1 • Published 4 years ago

react-videojs-hook v1.0.1

Weekly downloads
171
License
MIT
Repository
github
Last release
4 years ago

react-videojs-hook

A React hook for video.js

NPM JavaScript Style Guide

Install using npm

npm install --save react-videojs-hook
npm install --save video.js

Install using yarn

yarn add react-videojs-hook
yarn add video.js

Usage

import React from 'react';
import { useVideojs } from 'react-videojs-hook';

import 'video.js/dist/video-js.css';

const App = () => {
  const onPlay = (currentTime?: number) => {
    console.log("Video played at: ", currentTime);
  };

  const onPause = (currentTime?: number) => {
    console.log("Video paused at: ", currentTime);
  };

  const onEnd = (currentTime?: number) => {
    console.log(`Video ended at ${currentTime}`);
  };

  const onTimeUpdate = (currentTime: number) => {
    console.log(`Video current time is ${currentTime}`)
  };

  const { vjsId, vjsRef, vjsClassName } = useVideojs({
    src: 'https://www.radiantmediaplayer.com/media/big-buck-bunny-360p.mp4',
    controls: true,
    autoplay: true,
    responsive: true,
    bigPlayButtonCentered: true,
    onPlay,
    onPause,
    onEnd,
    onTimeUpdate,
  });


  // wrap the player in a div with a `data-vjs-player` attribute
  // so videojs won't create additional wrapper in the DOM
  // see https://github.com/videojs/video.js/pull/3856
  return (
    <div data-vjs-player>
      <video ref={vjsRef} id={vjsId} className={vjsClassName}></video>
    </div>
  )
}

Hook Parameters

ParamDescriptionRequiredDefault
srcThe video source URLtrue
classNameclassName to customize video player UIfalse
sourcesThe sources for a media asset. [{src: 'http://ex.com/video.mp4', type: 'video/mp4'}]falsefalse
aspectRatioThe value to set the Player's aspect ratio tofalse
controlsSet to true or false to display native player controlsfalsefalse
autoplaySet the autoplay option, true or falsefalsefalse
textTrackSettingsManipulate Text Tracks settings.false
defaultVolumeVideo player initial volumefalsefalse
responsiveSet responsive mode to add and remove classes based on its size breakpointsfalsefalse
responsiveSet responsive mode to add and remove classes based on its size breakpointsfalsefalse
widthSet player widthfalseauto
heightSet player heightfalseauto
heightSet player heightfalseauto
bigPlayButtonSet initial play button that shows before the video has playedfalsetrue
onReadyTriggered when player is loaded and ready to playfalse
onPlayTriggered when player's play button is clickedfalse
onPauseTriggered when player's pause button is clickedfalse
onTimeUpdateTriggered every time play time updatesfalse
onSeekingTriggered on player seeking to a different play timefalse
onSeekedTriggered on player seeking completion to a different play timefalse
onEndTriggered when video finishes playingfalse

How to contribute

To contribute, fork this repo to your private repository and create a pull request based on the feature you want to add.

License

MIT © Hector101