Frontend School

Simple Video Playback Control

Machine Coding
easy

Simple Video Playback Control

Easy
React
TypeScript
UI
State Management

Overview

Innovaccer's platform frequently utilizes educational and training videos to onboard new users or explain complex features. To enhance the user experience, we need a robust yet simple component to manage video playback. This problem focuses on building a foundational video player control component that displays essential information and allows basic interaction, simulating a real video's state and progress.

What you need to do / Task

Your task is to create a React component named VideoPlayer that displays video information and provides basic playback controls. You will simulate video playback without an actual <video> HTML element.

  1. Render Video Metadata: Display the video's title and total duration.
  2. Play/Pause Control: Implement a button that toggles the video's playback state between "playing" and "paused". The button text should reflect the current action (e.g., "Play" when paused, "Pause" when playing).
  3. Current Time Display: Show the current playback time, updating every second when the video is "playing".
  4. Progress Bar: Visualize the video's progress with a simple horizontal bar that fills up as the currentTime advances.
  5. Component Cleanup: Ensure that any setInterval timers are properly cleared when the component unmounts to prevent memory leaks.

UI/UX expectations

  • Layout: The component should have a clear, simple layout. A suggested structure includes the video title at the top, followed by control buttons (like Play/Pause), then the current time and total duration, and finally the progress bar.
  • Interactions: The Play/Pause button should be clearly clickable.
  • Accessibility: The Play/Pause button should have descriptive text that changes based on its current function.

Acceptance criteria

  • The VideoPlayer component correctly displays the provided video title and total duration.
  • Clicking the Play/Pause button toggles the video's playback state.
  • When playing, the current time display updates every second, incrementing until it reaches the total duration.
  • When paused, the current time display stops updating.
  • The progress bar visually represents the currentTime relative to the totalDuration, filling from left to right.
  • The component handles edge cases like reaching the end of the video (e.g., stopping playback at duration).
  • No console errors or warnings related to memory leaks (e.g., un-cleared setInterval).

Constraints

Constraints & assumptions

  • Data: The video title and duration will be provided as props to the VideoPlayer component. The duration will be in seconds.
  • Simulation: You are NOT expected to use an actual HTML <video> element. Simulate playback entirely using React state and setInterval.
  • Environment: The solution should be implemented using React and TypeScript.
  • Styling: Basic CSS for layout and visual clarity is sufficient. Focus on functionality over elaborate styling.

Out of scope

  • Volume controls, mute/unmute functionality.
  • Seeking functionality (dragging the progress bar to jump to a specific time).
  • Fullscreen mode or picture-in-picture.
  • Loading states, error handling, or network requests for video data.
  • Complex responsive design or cross-browser compatibility beyond basic layout.

What interviewers evaluate

  • State Management: Effective use of useState and useEffect to manage playback state (playing/paused, current time) and ensure proper component lifecycle handling (cleanup).
  • React Fundamentals: Correct application of React component structure, props, and event handling.
  • Code Quality: Readability, maintainability, and organization of the codebase, including appropriate use of TypeScript types.
  • Problem Solving: Ability to break down the problem into smaller, manageable parts and implement a functional solution within the given constraints.

Loading editor...