Skip to content

Root: ui|v2.5|src|components|ScenePlayer: ScenePlayer.tsx

Serechops edited this page Apr 10, 2024 · 2 revisions

ScenePlayer.tsx

The ScenePlayer.tsx file contains a React functional component ScenePlayer, which is responsible for rendering and managing the video player interface. This component integrates with the video.js library and includes various features such as interactive controls, scene markers, captions, hotkeys, and more.

  1. Imports:

    • The component imports various modules and libraries including React, video.js, custom hooks, and utility functions.
  2. Helper Functions:

    • handleHotkeys: Handles keyboard events for controlling the video player, including seeking, playback control, volume adjustment, fullscreen toggle, etc.
    • getMarkerTitle: Helper function to generate a title for scene markers based on primary and secondary tags.
  3. Component Props:

    • IScenePlayerProps: Defines the props interface for the ScenePlayer component, including scene data, autoplay, event handlers, etc.
  4. Component Definition:

    • The ScenePlayer component is defined as a functional component.
    • It uses various hooks such as useState, useRef, useContext, and useEffect for managing state and side effects.
    • The component initializes the video player using video.js with specific options and plugins.
    • It sets up event handlers for player events like play, pause, time update, fullscreen change, etc.
    • The component manages the interaction with scene markers, captions, interactive elements, and other UI features.
    • It includes conditional rendering for interactive status, scrubber, and other UI elements based on specific conditions.
    • Event handlers and side effects are defined to handle player actions, scene changes, interactive state, etc.
  5. Rendering:

    • The component renders the video player interface along with additional UI elements like interactive status, scrubber, etc.
    • Conditional rendering is used to display specific UI elements based on certain conditions like the availability of scene data, interactive status, screen orientation, etc.

Example Modification:

Suppose you want to add support for displaying thumbnails for scene markers in the scrubber. You can modify the ScenePlayerScrubber component to include thumbnails for each scene marker. Additionally, you can enhance the marker rendering logic to handle thumbnail display based on specific conditions.

// Example modification code for ScenePlayerScrubber component
// Add thumbnail display for scene markers
const ScenePlayerScrubber: React.FC<IScenePlayerScrubberProps> = ({
  file,
  scene,
  time,
  onSeek,
  onScroll,
}) => {
  return (
    <div className="scene-player-scrubber">
      {scene.scene_markers.map((marker) => (
        <div
          key={marker.seconds}
          className="scene-marker"
          style={{ left: `${(marker.seconds / file.duration) * 100}%` }}
        >
          <img src={marker.thumbnailUrl} alt="Marker Thumbnail" />
          <div className="marker-label">{marker.title}</div>
        </div>
      ))}
    </div>
  );
};

Explanation:

With this modification, the ScenePlayerScrubber component will display thumbnails along with titles for each scene marker in the scrubber. The modification enhances the user experience by providing visual cues for scene transitions and important points in the video content.

Clone this wiki locally