Frontend School

Interactive Audio Player Widget

Machine Coding
medium

Interactive Audio Player Widget

Medium
Audio Player
UI/UX
State Management
Event Handling
React
TypeScript

Overview

In a world increasingly reliant on digital media, a robust and intuitive audio player is fundamental to any media platform. This problem challenges you to build a core component of such a platform: an interactive audio player widget. Your solution will demonstrate your ability to manage complex UI state, interact with browser APIs, and deliver a seamless user experience, which is critical for user engagement in products like music streaming or podcast applications.

What you need to do / Task

Your task is to implement a functional audio player component that can play a list of audio tracks.

  1. Display Track Information: Show the current track's title and artist.
  2. Playback Controls: Implement 'Play', 'Pause', 'Next Track', and 'Previous Track' buttons.
  3. Progress Bar: Display the current playback progress with a slider, showing current time and total duration. The slider should be interactive, allowing users to seek to different parts of the track.
  4. Volume Control: Implement a volume slider to adjust the audio output.
  5. Looping Functionality: Add a toggle button to loop the current track.

UI/UX expectations

  • Layout: The player should have a clean, intuitive layout, similar to common audio players. Track information should be clearly visible, and controls should be easily accessible.
  • Interactions:
    • 'Play' button should turn into 'Pause' when playing, and vice-versa.
    • The progress bar should update in real-time during playback.
    • Users should be able to drag the progress slider to seek.
    • Users should be able to drag the volume slider to change volume.
    • The loop button should visually indicate its active state.
  • Accessibility (Optional but good to consider): Basic keyboard navigation for controls (e.g., Space for play/pause) is a plus.

Acceptance criteria

  • Clicking the 'Play' button starts audio playback and changes the button icon/text to 'Pause'.
  • Clicking the 'Pause' button stops audio playback and changes the button icon/text to 'Play'.
  • The progress bar visually updates as the audio plays.
  • Dragging the progress bar slider changes the current playback position.
  • The displayed current time and total duration accurately reflect the audio state.
  • Clicking 'Next Track' switches to the subsequent track in the list and starts playing it (if currently playing).
  • Clicking 'Previous Track' switches to the preceding track in the list and starts playing it (if currently playing).
  • Dragging the volume slider adjusts the audio output volume.
  • Clicking the 'Loop' button toggles the looping behavior for the current track.
  • When a track finishes, if looping is off, it should stop or move to the next track if available.

Constraints

Constraints & assumptions

  • You will be provided with a mock array of audio track objects.
  • Use the browser's native HTMLAudioElement API for audio playback. Do not use external audio libraries.
  • The focus is on the frontend UI and state management; no backend integration is required.
  • Assume all audio files are valid and load correctly. Error handling for audio loading is out of scope.
  • The solution should be implemented using React and TypeScript.
  • Target completion time: ~45 minutes.

Out of scope

  • Complex playlist management (e.g., shuffle, repeat all).
  • Custom audio effects or equalizers.
  • Advanced accessibility features beyond basic button/slider interaction.
  • Persistent state management (e.g., saving user preferences).

What interviewers evaluate

  • Component Design & State Management: How well the component is structured, and how effectively state is managed to reflect UI and audio player status.
  • Interaction with Browser APIs: Correct and efficient use of the HTMLAudioElement API for playback, seeking, and volume control.
  • Event Handling: Proper implementation of event listeners for UI interactions and audio events (e.g., timeupdate, ended).
  • Code Quality: Readability, maintainability, and adherence to best practices in React and TypeScript.

Loading editor...