# video-provider

> React state manager for videos

Latest version **1.1.0** (published 2023-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install video-provider
pnpm add video-provider
yarn add video-provider
bun add video-provider
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-07-21 |
| First published | 2022-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vahagn |
| Maintainers | vhgn |
| Keywords | react, video, provider |

## Links

- npm: https://www.npmjs.com/package/video-provider
- Repository: https://github.com/vhgn/video-provider
- npm.io page: https://npm.io/package/video-provider

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^18.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-07-21
- 1.0.9 — 2023-02-02
- 1.0.8 — 2022-12-22
- 1.0.7 — 2022-12-14
- 1.0.6 — 2022-12-14
- 1.0.5 — 2022-11-29
- 1.0.4 — 2022-11-29
- 1.0.2 — 2022-11-29
- 1.0.1 — 2022-11-29
- 1.0.0 — 2022-11-29

## README

# Description

This is a provider, which listens to specific events of `<video>` element and updates corresponding states.
It helps you render your UI based on states and not worry about any triggering changes.

[![Edit video-provider-example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/video-provider-example-zu0hdd?fontsize=14&hidenavigation=1&theme=dark)

# Usage

```tsx
import { useContext, useRef } from "react";
import { VideoProvider, VideoContext } from "video-provider";

const Page = () => {
  // Using these states will rerender your component on change
  const {
    now,
    duration,
    paused,
    muted,
    volume,

    play,
    pause,
    mute,
    setVolume
  } = useContext(VideoContext);

  return (
    <div>
      <p>
        Time {now.toFixed()}:{duration.toFixed()}
      </p>
      <p>Player is {paused ? "paused" : "playing"}</p>
      <p>Sound is {muted ? "muted" : "not muted"}</p>
      <p>Volume is {volume * 100}%</p>

      <button onClick={paused ? play : pause}>
        {paused ? "Play" : "Pause"}
      </button>
      <button onClick={() => mute(!muted)}>{muted ? "Unmute" : "Mute"}</button>
      <input
        type="number"
        placeholder="Volume"
        onInput={(e) => {
          const newVolume = Number(e.currentTarget.value) / 100;

          if (newVolume > 1) return setVolume(1);
          if (newVolume < 0) return setVolume(0);
          setVolume(newVolume);
        }}
      />
    </div>
  );
};

export const App = () => {
  const ref = useRef(null);

  return (
    <div>
      <video
        controls
        ref={ref}
        src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
      />
      <VideoProvider element={ref}>
        <Page />
      </VideoProvider>
    </div>
  );
};
```

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