Socket
Socket
Sign inDemoInstall

use-video-player-hook

Package Overview
Dependencies
2
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-video-player-hook

custom react hook helps to create custom video player


Version published
Weekly downloads
22
increased by46.67%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

use-video-player

custom react hook helps you to build custome video player

Install

yarn add use-video-player-hook or npm i use-video-player-hook

Usage

 const videoElement = useRef(null);
const {
    playerState,
    togglePlay,
    handleOnTimeUpdate,
    handleVideoProgress,
    handleVideoSpeed,
    toggleMute,
} = useVideoPlayer(videoElement);


return (
    <div>
        <div>
            <video
                src={src}
                ref={videoElement}
                onTimeUpdate={handleOnTimeUpdate}
            />
            <div>
                <button onClick={togglePlay}>
                    {!playerState.isPlaying ? (
                        <span>Play</span>
                    ) : (
                        <span>Pause</span>
                    )}
                </button>
                <input
                    type="range"
                    min="0"
                    max="100"
                    value={playerState.progress}
                    onChange={(e) => handleVideoProgress(e)}
                />
                <select
                    value={playerState.speed}
                    onChange={(e) => handleVideoSpeed(e)}
                >
                    <option value="0.50">0.50x</option>
                    <option value="1">1x</option>
                    <option value="1.25">1.25x</option>
                    <option value="2">2x</option>
                </select>
                <button onClick={toggleMute}>
                    {!playerState.isMuted ? (
                        <span>Mute</span>
                    ) : (
                        <span>Unmute</span>
                    )}
                </button>
            </div>
        </div>
    </div>
);

All you need is to pass videoElement ref as a parameter

     const videoElement = useRef(null);
     const {
      playerState,
      togglePlay,
      handleOnTimeUpdate,
      handleVideoProgress,
      handleVideoSpeed,
      toggleMute,
    } = useVideoPlayer(videoElement);

Metadata

package on npm https://npmjs.com/package/use-video-player-hook

Show your support

Give a ⭐️ if this project helped you!

Keywords

FAQs

Last updated on 12 Aug 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc