Overview
In this round, you will build a functional and user-friendly audio player component. This problem focuses on demonstrating your ability to manage component state, interact with native browser APIs (specifically the HTML Audio element), and create a responsive user interface that provides a good user experience. A well-designed audio player is a foundational component in many media-rich applications, highlighting your practical engineering skills.
What you need to do / Task
Your primary goal is to implement a React component that functions as a single-track audio player. The component should:
- Implement Play/Pause Functionality: A button to toggle between playing and pausing the audio track.
- Display Playback Progress: Show the current playback time and the total duration of the track.
- Create a Seekable Progress Bar: A visual progress bar that updates in real-time as the audio plays. Users should be able to click or drag on this bar to seek to different positions within the track.
- Manage Audio State: Ensure the UI accurately reflects the current state of the audio (e.g., button text changes, progress bar updates, time displays).
UI/UX expectations
- The player should have a clearly visible button that indicates whether the audio is currently playing or paused (e.g., 'Play' or 'Pause' text/icon).
- The progress bar should visually represent the elapsed time relative to the total duration. It should be interactive, allowing users to jump to a specific point in the audio by clicking on it.
- Current time and total duration should be displayed in a readable format, such as
MM:SS (e.g., 01:23).
- Basic styling is provided; focus on functionality and ensuring the UI elements are responsive to user interactions and audio events.
Acceptance criteria
- Clicking the play button starts audio playback and changes the button text/icon to 'Pause'.
- Clicking the pause button stops audio playback and changes the button text/icon to 'Play'.
- The progress bar updates smoothly and continuously as the audio plays.
- The current time display updates in real-time during playback.
- The total duration is displayed correctly once the audio metadata is loaded.
- Clicking anywhere on the progress bar (or dragging the thumb) jumps the audio playback to that corresponding position.
- When the audio finishes playing, it should automatically pause and reset its state (e.g., button shows 'Play', current time resets or stays at end).