Frontend School

Adaptive Video Player with Dynamic Controls

Machine Coding
hard

Adaptive Video Player with Dynamic Controls

Hard
React
Video
Media API
State Management
UI/UX

Overview

Modern web applications, especially those dealing with rich content like Razorpay's product demos or educational materials, require robust and highly customizable video players. Building a custom player not only offers full control over the user experience but also demonstrates a deep understanding of browser media APIs, state management, and component architecture. This problem challenges you to build a functional, feature-rich video player with adaptive controls, mirroring the complexity and user expectations of a production-grade media platform.

What you need to do / Task

You are tasked with building a VideoPlayer React component that renders a video and a comprehensive set of custom controls. The player should be interactive and reflect the current state of the video.

  1. Core Playback Controls: Implement functional Play/Pause and Mute/Unmute buttons.
  2. Progress Bar & Time Display: Create a seekable progress bar that accurately reflects the video's current playback position. Display the current time and total duration of the video in a user-friendly format (e.g., MM:SS).
  3. Playback Speed Control: Provide a dropdown or a set of buttons to allow users to change the video playback speed (e.g., 0.5x, 1x, 1.5x, 2x).
  4. Video Quality Selection: Implement a mechanism (e.g., dropdown) to switch between different video qualities (e.g., 360p, 720p, 1080p). Switching quality should load a different video source URL while attempting to maintain the current playback position.
  5. Fullscreen Toggle: Add a button to toggle the video player into and out of fullscreen mode.
  6. Control Visibility: The control bar should appear when the user hovers over the video player area and disappear after a short delay when the mouse moves out, or after a period of inactivity.

UI/UX expectations

  • The video player should have a clean, modern look. Controls should be intuitively placed, ideally overlaying the bottom part of the video or appearing just below it.
  • The progress bar should update smoothly and be easily draggable for seeking.
  • Speed and quality selectors should be clear and easy to interact with (e.g., using dropdowns or distinct buttons).
  • The fullscreen toggle should be a recognizable icon.
  • Ensure basic visual feedback for interactive elements (e.g., hover states).
  • When the video ends, the play button should ideally transform into a 'Replay' button, and the progress bar should reset.

Acceptance criteria

  • Video plays and pauses correctly via the custom control.
  • Audio mutes and unmutes, with the control icon reflecting the state.
  • Progress bar accurately displays current time, total duration, and allows seeking.
  • Playback speed can be changed, and the video's speed updates accordingly.
  • Video quality can be switched dynamically, loading a new source while preserving playback time.
  • Fullscreen mode can be entered and exited, with the video element correctly scaling.
  • Video controls appear on hover/activity and hide on inactivity.
  • Upon video completion, the player state resets appropriately (e.g., time to 0, play button to 'Replay').

Constraints

Constraints & assumptions

  • You must use the native HTML <video> element and its associated JavaScript API (e.g., HTMLVideoElement properties and events).
  • The solution must be implemented using React. No external UI component libraries (e.g., Material UI, Ant Design) are allowed; build components from scratch.
  • Assume modern browser compatibility for HTML5 video and Fullscreen API.
  • Use the provided mock video data structure for different qualities.
  • Focus on functional correctness and clean, maintainable code within the given time budget (~45 minutes).
  • The video player should occupy a fixed width/height for simplicity (e.g., 640px x 360px).

Out of scope

  • Volume slider (beyond simple mute/unmute).
  • Picture-in-picture functionality.
  • Advanced error handling for video loading failures or network issues.
  • Server-side video streaming or DRM integration.
  • Complex responsive design for various screen sizes (focus on a desktop view).

What interviewers evaluate

  • Functional Correctness: All required video controls and features (play/pause, seek, speed, quality, fullscreen, control visibility) work as specified.
  • React Best Practices: Effective use of React hooks (useState, useEffect, useRef), proper component composition, and efficient state management.
  • Browser API Knowledge: Correct and robust interaction with the HTMLVideoElement API and Fullscreen API.
  • Code Quality & Architecture: Clean, readable, well-structured, and modular code with appropriate separation of concerns.
  • Problem Solving: Ability to handle complex interactions like dynamic source switching while maintaining playback state and managing control visibility.

Loading editor...