1.0.2 β€’ Published 6 months ago

react-player-plugin-prompter v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

πŸ“š react-player-plugin-prompter

React Player Plugin enhances react-player by adding robust subtitle control features, making it ideal 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

PropTypeDescription
mode'line' | 'block'Determines how subtitles are displayed: line-by-line or in block mode.
scriptsScript<LanguageCode>[]Array of subtitle scripts with timings, translations, and metadata.
selectedLanguagesLanguageCode[]Array of languages to display for subtitles (e.g., ['en', 'ko']).
seekTo(timeInSeconds: number) => voidFunction to seek the video to a specific time (in seconds).
currentTimenumberCurrent playback time in seconds.
onClickScript(script, index) => voidCallback function triggered when a subtitle is clicked.
onSelectWord(word, script, index) => voidCallback function triggered when a word within a subtitle is selected.
containerStyleContainerStyleCustom styles for the subtitle container (width, height, padding, background color, etc.).
textStyleTextStyleStyles for the subtitle text (color, font size, active color, etc.).
timeStyleTimeStyleStyles for the timestamp button (color, font, background color, etc.).
PrevButton({ onClick }: { onClick: () => void }) => JSX.ElementCustom button to move to the previous subtitle.
NextButton({ onClick }: { onClick: () => void }) => JSX.ElementCustom button to move to the next subtitle.
FocusButton({ isFocus, setIsFocus }: { isFocus: boolean, setIsFocus: Dispatch<SetStateAction<boolean>> }) => JSX.ElementButton 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.

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

7 months ago

0.0.3

7 months ago

0.0.2

8 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.1

9 months ago