Frontend School

Interactive Audio Player Component

Machine Coding
medium

Interactive Audio Player Component

Medium
React
UI
Audio
State Management
Hooks

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:

  1. Implement Play/Pause Functionality: A button to toggle between playing and pausing the audio track.
  2. Display Playback Progress: Show the current playback time and the total duration of the track.
  3. 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.
  4. 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).

Constraints

Constraints & assumptions

  • You must use React for building the UI component.
  • Leverage the native HTMLAudioElement API for audio playback control. Avoid external audio libraries unless you can justify why one is strictly necessary and have time to integrate it.
  • The problem focuses on playing a single audio track, provided as a URL.
  • Assume a modern browser environment where HTMLAudioElement is fully supported.
  • Focus on functional correctness and clean, maintainable code.

Out of scope

  • Playlist management (e.g., next/previous track).
  • Volume control.
  • Advanced error handling for audio loading failures (e.g., network issues).
  • Complex visualizers or equalizer effects.
  • Backend integration or fetching track data from an API.

What interviewers evaluate

  • Correctness and Completeness: Does the audio player function as specified, handling play/pause, progress, and seeking accurately?
  • React Proficiency: Effective use of React hooks (useState, useEffect, useRef) and managing component lifecycle for audio interactions.
  • Code Quality: Readability, modularity, and maintainability of the React component and associated logic.
  • User Experience: How well the UI responds to user input and audio events, providing a smooth interaction.

Loading editor...