Skip to content

Patchwork-Archive/react-srv3

Repository files navigation

react-srv3

This is a fork of HoloArchivist/react-srv3 that is being used for Patchwork-Browser

React component to render YouTube SRV3 closed captions

NPM

View demo

Install

yarn add react-srv3

Usage

import { CaptionsRenderer } from 'react-srv3';

<CaptionsRenderer
  srv3="<?xml ..." // SRV3 XML string
  currentTime={0}  // Current video time in seconds
/>

Example

import React from 'react';
import { CaptionsRenderer } from 'react-srv3';

const VideoPlayer = () => {
  const [currentTime, setCurrentTime] = React.useState(0);
  const [captionsText, setCaptionsText] = React.useState('');

  React.useEffect(() => {
    fetch('<srv3 captions file>')
      .then(res => res.text())
      .then(setCaptionsText)
  }, []);

  return (
    <div style={{ position: 'relative', width: 640, height: 360 }}>
      <video
        src="video.mp4"
        style={{ position: 'absolute', width: '100%', height: '100%' }}
        onTimeUpdate={(e) => setCurrentTime(e.target.currentTime)}
      />
      <CaptionsRenderer srv3={captionsText} currentTime={currentTime} />
    </div>
  )
}

License

MIT © hizkifw

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published