Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-videojs-hook

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-videojs-hook

A React hook for video.js

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 27 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc