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.
- Display Track Information: Show the current track's title and artist.
- Playback Controls: Implement 'Play', 'Pause', 'Next Track', and 'Previous Track' buttons.
- 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.
- Volume Control: Implement a volume slider to adjust the audio output.
- 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.