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

react-player-plugin-prompter

v0.0.5

Published

A React Player plugin specialized for subtitle handling

Downloads

284

Readme

📚 react-player-plugin-prompter

react-player-plugin-prompter is a powerful, open-source library that enhances the capabilities of react-player by adding subtitle synchronization, sentence navigation, and word selection features. It is particularly useful for educational content and language learning platforms.


🚀 Key Features

  • Subtitle Synchronization: Automatically scrolls subtitles based on the current playback time.
  • Line and Block Modes: Provides options to display subtitles either line-by-line or in block mode.
  • Subtitle Navigation Buttons: Easily navigate to the previous or next subtitle.
  • Word Selection Feature: Select specific words within subtitles for additional interactions.
  • Focus Mode: Enables a mode where only the current subtitle is highlighted, helping users focus on a single line at a time.

🛠️ Installation

npm install react-player-plugin-prompter
# or
yarn add react-player-plugin-prompter

📖 Usage Example

Basic Example

import React, { useState, useRef } from 'react';
import ReactPlayer from 'react-player';
import { ReactScriptPlayer } from 'react-player-plugin-prompter';
import scriptsMockData from './mocks/scriptsMockData';

function App() {
  const playerRef = useRef<ReactPlayer | null>(null);
  const [currentTime, setCurrentTime] = useState(0);
  const [isPlaying, setIsPlaying] = useState(false);

  const seekTo = (timeInSeconds: number) =>
    playerRef.current?.seekTo(timeInSeconds, 'seconds');

  return (
    <div>
      <ReactPlayer
        ref={playerRef}
        url="https://example.com/video.mp4"
        playing={isPlaying}
        onProgress={({ playedSeconds }) => setCurrentTime(playedSeconds)}
        controls
      />
      <ReactScriptPlayer
        mode="line"
        scripts={scriptsMockData}
        selectedLanguages={['en', 'ko']}
        seekTo={seekTo}
        currentTime={currentTime}
        onClickScript={(script, index) => console.log(script, index)}
        onSelectWord={(word, script, index) => console.log(word, script, index)}
      />
    </div>
  );
}

export default App;

🔧 Props Explanation

| Prop | Type | Description | |---------------------|-------------------------------------------------------------------------------------------------------|-------------| | mode | 'line' | 'block' | Determines how subtitles are displayed: line-by-line or in block mode. | | scripts | Script<LanguageCode>[] | Array of subtitle scripts with timings, translations, and metadata. | | selectedLanguages | LanguageCode[] | Array of languages to display for subtitles (e.g., ['en', 'ko']). | | seekTo | (timeInSeconds: number) => void | Function to seek the video to a specific time (in seconds). | | currentTime | number | Current playback time in seconds. | | onClickScript | (script, index) => void | Callback function triggered when a subtitle is clicked. | | onSelectWord | (word, script, index) => void | Callback function triggered when a word within a subtitle is selected. | | containerStyle | ContainerStyle | Custom styles for the subtitle container (width, height, padding, background color, etc.). | | textStyle | TextStyle | Styles for the subtitle text (color, font size, active color, etc.). | | timeStyle | TimeStyle | Styles for the timestamp button (color, font, background color, etc.). | | PrevButton | ({ onClick }: { onClick: () => void }) => JSX.Element | Custom button to move to the previous subtitle. | | NextButton | ({ onClick }: { onClick: () => void }) => JSX.Element | Custom button to move to the next subtitle. | | FocusButton | ({ isFocus, setIsFocus }: { isFocus: boolean, setIsFocus: Dispatch<SetStateAction<boolean>> }) => JSX.Element | Button to toggle focus mode on/off. |


📂 Type Definitions

LanguageCode

type LanguageCode = 'en' | 'ko' | 'ja' | 'de' | 'fr' | 'es';

Script

type Script<T extends string = LanguageCode> = Partial<Record<T, string>> & {
  startTimeInSecond: number;
  durationInSecond: number;
  isHighlighted: boolean;
};

📂 Data Structure Example (scriptsMockData)

export const scriptsMockData = [
  {
    en: 'Hello, welcome to the video!',
    ko: '안녕하세요, 비디오에 오신 것을 환영합니다!',
    startTimeInSecond: 0,
    durationInSecond: 5,
    isHighlighted: true,
  },
  {
    en: 'This is a subtitle example.',
    ko: '이것은 자막 예제입니다.',
    startTimeInSecond: 6,
    durationInSecond: 4,
    isHighlighted: false,
  },
];

🎨 Styling Customization Example

<ReactScriptPlayer
  mode="block"
  scripts={scriptsMockData}
  selectedLanguages={['en']}
  seekTo={seekTo}
  currentTime={currentTime}
  textStyle={{
    color: '#333',
    fontSize: '16px',
    fontWeight: 'bold',
    activeColor: '#f5f3ff',
  }}
  timeStyle={{
    color: '#5a5a5a',
    fontSize: '14px',
    backgroundColor: '#ddd6fe',
    borderRadius: '5px',
    padding: '4px',
  }}
  containerStyle={{
    width: '100%',
    height: 'auto',
    padding: '10px',
    backgroundColor: '#f0f0f0',
  }}
/>

📄 License

This library is licensed under the MIT License.