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.
- Core Playback Controls: Implement functional Play/Pause and Mute/Unmute buttons.
- 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).
- 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).
- 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.
- Fullscreen Toggle: Add a button to toggle the video player into and out of fullscreen mode.
- 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').