# react-videojs-hook

> A React hook for video.js

Latest version **1.0.1** (published 2020-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-videojs-hook
pnpm add react-videojs-hook
yarn add react-videojs-hook
bun add react-videojs-hook
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-07-27 |
| First published | 2020-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 31.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Hector101 |
| Maintainers | hector101 |
| Keywords | react-videojs-hook, react hook, videojs, video.js, video player |

## Links

- npm: https://www.npmjs.com/package/react-videojs-hook
- Repository: https://github.com/Hector101/react-videojs-hook
- Homepage: https://github.com/Hector101/react-videojs-hook#readme
- Issues: https://github.com/Hector101/react-videojs-hook/issues
- npm.io page: https://npm.io/package/react-videojs-hook

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-07-27
- 1.0.0 — 2020-07-27

## README

# react-videojs-hook

> A React hook for video.js

[![NPM](https://img.shields.io/npm/v/react-videojs-hook.svg)](https://www.npmjs.com/package/react-videojs-hook) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install using npm

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

## Install using yarn

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

## Usage

```tsx
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

Param | Description | Required | Default
---- | ----------- | -------- | -------
`src` | The video source URL | `true`
`className` | className to customize video player UI | `false`
`sources` | The sources for a media asset. `[{src: 'http://ex.com/video.mp4', type: 'video/mp4'}]` | `false` | `false`
`aspectRatio` | The value to set the Player's aspect ratio to | `false`
`controls` | Set to `true` or `false` to display native player controls | `false` | `false`
`autoplay` | Set the autoplay option, `true` or `false` | `false` | `false`
`textTrackSettings` |  Manipulate Text Tracks settings. | `false`
`defaultVolume` | Video player initial volume | `false` | `false`
`responsive` | Set responsive mode to add and remove classes based on its size breakpoints | `false` | `false`
`responsive` | Set responsive mode to add and remove classes based on its size breakpoints | `false` | `false`
`width` | Set player width | `false` | `auto`
`height` | Set player height | `false` | `auto`
`height` | Set player height | `false` | `auto`
`bigPlayButton` | Set initial play button that shows before the video has played | `false` | `true`
`onReady` | Triggered when player is loaded and ready to play | `false`
`onPlay` | Triggered when player's play button is clicked | `false`
`onPause` | Triggered when player's pause button is clicked | `false`
`onTimeUpdate` | Triggered every time play time updates | `false`
`onSeeking` | Triggered on player seeking to a different play time | `false`
`onSeeked` | Triggered on player seeking completion to a different play time | `false`
`onEnd` | Triggered when video finishes playing | `false`

## 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](https://github.com/Hector101)

---
_Source: https://npm.io/package/react-videojs-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
