Frontend School

Advanced Audio Segment Selector

Machine Coding
hard

Advanced Audio Segment Selector

Hard
Range Slider
UI Components
Time Selection
Accessibility
React

Overview

Spotify's new "Producer Mode" empowers artists and podcasters to define specific loopable segments within their tracks. These segments can be used for promotional snippets, interactive fan experiences, or educational content. To facilitate this, we need a robust and accessible UI component that allows precise selection of audio segments within a given track's duration.

This problem focuses on building an advanced range slider component that handles time-based values, provides clear visual feedback, and ensures comprehensive keyboard accessibility, matching the high bar for Spotify's user experience.

What you need to do / Task

  1. Component Implementation: Create a controlled React functional component named AudioSegmentSelector that accepts the following props:
    • min: The minimum selectable time in seconds (e.g., 0).
    • max: The maximum selectable time in seconds (e.g., total duration).
    • initialStart: The initial start time of the segment in seconds.
    • initialEnd: The initial end time of the segment in seconds.
    • duration: The total duration of the audio track in seconds (for context).
    • onSegmentChange: A callback function (start: number, end: number) => void that is triggered when the selected segment changes.
    • width: An optional prop for the pixel width of the slider track (default 600px).
  2. Visual Representation: Render two draggable "thumb" elements representing the start and end of the selected segment. Visually indicate the selected range between these two thumbs.
  3. Dynamic Time Display: Display the current start and end times (e.g., "0:30 - 1:15") above the slider. This display must update dynamically as the thumbs are moved.
  4. Dragging Interaction: Allow users to drag each thumb independently using the mouse.
  5. Constraint Enforcement: Ensure that the start thumb cannot be dragged past the end thumb, and vice-versa. The start value must always be less than or equal to the end value (start <= end). Also, ensure thumbs cannot be dragged outside the min and max boundaries.
  6. Keyboard Accessibility: Implement keyboard navigation for each thumb:
    • ArrowLeft / ArrowRight: Move the respective thumb by a small increment (e.g., 1 second).
    • Shift + ArrowLeft / Shift + ArrowRight: Move the respective thumb by a larger increment (e.g., 10 seconds).
  7. Debounced Callback: Debounce the onSegmentChange callback to prevent excessive updates while the user is actively dragging or using keyboard controls.

UI/UX expectations

  • Clean Design: The component should have a clean, modern aesthetic, aligning with Spotify's design principles (minimal styling is provided, focus on functionality).
  • Thumb Distinction: Thumbs should be visually distinct (e.g., circular) and provide clear visual feedback on hover/focus.
  • Selected Range: The segment between the thumbs should have a distinct background color to clearly indicate the selected range.
  • Focus States: Implement clear focus states for thumbs to aid keyboard navigation.
  • Accessibility: Use appropriate ARIA attributes (e.g., role="slider", aria-valuenow, aria-valuemin, aria-valuemax, aria-label, aria-valuetext) to ensure the component is usable by assistive technologies.

Acceptance criteria

  • The AudioSegmentSelector component renders correctly with initialStart and initialEnd values.
  • Dragging either thumb updates the displayed time and the visual selected range.
  • Thumbs cannot be dragged past each other; currentStart <= currentEnd is always maintained.
  • Thumbs cannot be dragged beyond the min and max boundaries.
  • Keyboard navigation (ArrowLeft/ArrowRight, Shift+ArrowLeft/Shift+ArrowRight) moves the corresponding thumb and updates the displayed values.
  • The onSegmentChange callback is invoked with the updated start and end values after a debounce period.
  • Correct ARIA attributes are applied to the thumb elements to enhance accessibility.
  • Time values are displayed in M:SS or MM:SS format (e.g., 0:05, 1:30).

Constraints

Constraints & assumptions

  • The total audio duration, min, max, initialStart, and initialEnd values will be provided in seconds.
  • Time values should be formatted and displayed to the user in M:SS or MM:SS format (e.g., 0:05, 1:30).
  • The slider will operate within a fixed pixel width (defaulting to 600px).
  • The component must be implemented using React and TypeScript.
  • No external UI component libraries (e.g., Material UI, Ant Design) should be used for the slider logic itself. Basic styling libraries or CSS modules are acceptable.
  • The onSegmentChange callback should be debounced by approximately 200ms.

Out of scope

  • Integration with actual audio playback or waveform visualization.
  • Advanced features like snap-to-grid, predefined markers, or touch-specific gestures (focus on mouse and keyboard).
  • Full visual parity with Spotify's production UI; basic functional styling is sufficient.

What interviewers evaluate

  • Functional Correctness: Does the range slider component work as specified, handling all interactions and constraints?
  • Component Design: Is the React component well-structured, using appropriate hooks, state management, and props?
  • User Experience: Are dragging and keyboard interactions smooth and intuitive, providing clear feedback?
  • Accessibility: Are ARIA attributes correctly applied, and is keyboard navigation robust?
  • Code Quality: Is the code clean, readable, performant, and maintainable, adhering to best practices?

Loading editor...