Advanced Audio Segment Selector
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.
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).start and end times (e.g., "0:30 - 1:15") above the slider. This display must update dynamically as the thumbs are moved.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.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).onSegmentChange callback to prevent excessive updates while the user is actively dragging or using keyboard controls.role="slider", aria-valuenow, aria-valuemin, aria-valuemax, aria-label, aria-valuetext) to ensure the component is usable by assistive technologies.AudioSegmentSelector component renders correctly with initialStart and initialEnd values.currentStart <= currentEnd is always maintained.min and max boundaries.ArrowLeft/ArrowRight, Shift+ArrowLeft/Shift+ArrowRight) moves the corresponding thumb and updates the displayed values.onSegmentChange callback is invoked with the updated start and end values after a debounce period.M:SS or MM:SS format (e.g., 0:05, 1:30).Constraints
duration, min, max, initialStart, and initialEnd values will be provided in seconds.M:SS or MM:SS format (e.g., 0:05, 1:30).width (defaulting to 600px).onSegmentChange callback should be debounced by approximately 200ms.Loading editor...