npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

duo-video

v1.0.4

Published

A react component for playing two videos synced. Finally rendered in webgl with an option to have an audiofile playing in sync aswell.

Downloads

9

Readme

DuoVideo

DuoVideo is a react component for playing two videos synced. Finally rendered in webgl with an option to have an audiofile playing in sync aswell. There is also an option to pass in your own fragment shader to control the final graphics.

Installation

Use npm or yarn to install DuoVideo.

yarn add duo-video

Usage

import DuoVideo from 'duo-video';

Loop to keep things in sync

ref is returned from DuoVideo component. Look below for details about playerState and playerDispatch

const intervalRef = useRef(null);

useEffect(() => {
  if (playerState.canBeSafelyPlayed) {
    intervalRef.current = setInterval(() => {
      if (ref && ref.current) {
        ref.current.checkBuffers(playerState, playerDispatch);
      }
    }, 2000);

    if (ref && ref.current) {
      ref.current.checkBuffers(playerState, playerDispatch);
    }
  }

  return () => {
    clearInterval(intervalRef.current);
  };
}, [playerState, playerDispatch]);

DuoVideoBuffer

{
  audioBuffer?: number,
  video0Buffer: number,
  video1Buffer: number,
}

VideoObj

{
  src: string, //hls src || if (mp4 = true) mp4 src
  fallback: string, //mp4 src
  mp4?: boolean, //force use mp4
}

DuoVideo Props

{
  videoPaths: Array<VideoObj>, // Length = 2
  audioPath?: string,
  frontRef: Object,
  currentIndex: number,
  onMediaCanBeSafelyPlayed: () => void,
  onMediaReady: (boolean) => void,
  fragmentShader?: string,
  videoResolution: Array<number>,
  showDebug?: boolean,
}

Player State

The component requires a reducer to be passed to public functions which are explained below.

const playerReducer = (state: Object, action: Object) => {
  switch (action.type) {
    case 'loading':
      return {
        ...state,
        isLoading: action.payload,
      };
    case 'playing':
      return {
        ...state,
        isPlaying: action.payload,
      };
    case 'safely-played':
      return {
        ...state,
        canBeSafelyPlayed: action.payload,
      };
    case 'mute':
      return {
        ...state,
        isMuted: action.payload,
      };
    default:
      throw new Error();
  }
};


const playerInitState = {
  isLoading: false,
  isPlaying: false,
  canBeSafelyPlayed: false,
  isMuted: false,
};

const [playerState, playerDispatch] = useReducer(playerReducer, playerInitState);

Component

<DuoVideo
  videoPaths={videoPaths} //required
  audioPath={audioPath} //optional - has to have the same duration as the videos
  ref={ref} //required
  frontRef={graphicsLayerRef} //required
  currentIndex={videoIndex} //required
  onMediaCanBeSafelyPlayed={onMediaCanBeSafelyPlayed} //required
  onMediaReady={setMediaIsReady} //required - called after media loaded
  videoResolution={[1280, 720]} //required
  showDebug //optional
/>

Public Fns

There are some public functions available that's needed to interact with the component.

start: () => void //triggers ios safe mobile init - has to be called first from a user action
getBuffers () => DuoVideoBuffer
play: (playerDispatch) => void
pause: (playerDispatch) => void
getDuration: () => number
setCurrentTime: (time: number, playerState, playerDispatch) => void
getCurrentTime: () => number
mute: (payload: boolean, playerDispatch) => void

License

ISC