Documentation Index
Fetch the complete documentation index at: https://mintlify.com/6xingyv/accompanist-lyrics-ui/llms.txt
Use this file to discover all available pages before exploring further.
KaraokeLyricsView is the central composable in Accompanist Lyrics UI. It renders an Apple Music-style scrolling lyrics panel that animates at the syllable level — each character dips, rises, and swells as its timing window passes. This guide walks through setting up the view, wiring a high-frequency position provider for smooth animation, understanding auto-scroll behavior, and handling tap and long-press gestures.
Basic Setup
KaraokeLyricsView needs a scroll-list state, a SyncedLyrics object, and a few callbacks. Here is the minimal complete example:
| Parameter | Type | Purpose |
|---|---|---|
listState | LazyListState | Controls and observes scroll position |
lyrics | SyncedLyrics | The full lyrics data including all lines |
currentPosition | () -> Int | Lambda returning current playback position in ms |
onLineClicked | (ISyncedLine) -> Unit | Called on a single tap — typically used to seek |
onLinePressed | (ISyncedLine) -> Unit | Called on a long press — typically used for share |
Providing the Current Position
ThecurrentPosition parameter is a lambda, not a State<Int>. This is the most important performance detail in the entire API.
Karaoke animation requires the canvas to redraw on every display frame — potentially 120 times per second. If currentPosition were an ordinary State<Int>, reading it inside the composable tree would invalidate the full composition on every frame and trigger a cascade of recompositions. Wrapping it in a lambda means the value is only read inside DrawScope during the draw phase, which bypasses recomposition entirely.
The pattern used in the sample PlayerScreen is:
awaitFrame() from kotlinx.coroutines.android suspends until the next display frame is scheduled. Using it inside a while (true) loop creates a frame-locked update loop that produces smooth animation without busy-waiting.Auto-Scrolling Behavior
KaraokeLyricsView automatically scrolls the list so the currently active line is always visible near the top of the viewport. The scrolling logic fires whenever lyricsFocusState.firstIndex changes — it first tries a cheap scrollBy to nudge the list if the target item is already on screen, and falls back to animateScrollToItem when the target is off-screen.
Two parameters control the spatial relationship between the focused line and the viewport edge:
offset: Dp(default32.dp) — vertical padding added to the start and end of the list viacontentPadding. This ensures the first and last lines are not flush against the screen edges.keepAliveZone: Dp(default100.dp) — extra space maintained above the focused line. The list is scrolled so that the focused line sits at leastoffset + keepAliveZonefrom the top of the viewport, keeping one or two context lines visible above it.
isManualScrolling flag detects this by checking listState.isScrollInProgress && !scrollInCode.value, so programmatic scrolls triggered by the library itself do not count as manual scroll.
Handling User Interactions
onLineClicked
onLineClicked receives the ISyncedLine that was tapped. The most common action is to seek the media player to the line’s start time:
ISyncedLine.start is the line’s start timestamp in milliseconds.
onLinePressed
onLinePressed receives the ISyncedLine that received a long press. Use this to show a context menu, a share sheet, or a copy dialog:
LyricsLineItem’s combinedClickable modifier, so standard accessibility semantics for click and long-click are correctly applied.
Enabling and Disabling Features
KaraokeLyricsView has four Boolean flags that toggle optional visual features:
| Flag | Default | Effect |
|---|---|---|
showTranslation | true | Renders KaraokeLine.translation or SyncedLine.translation below the line |
showPhonetic | true | Renders per-syllable phonetic text above each syllable |
useBlurEffect | true | Applies a Gaussian blur to inactive lines proportional to their distance from the focused line |
showDebugRectangles | false | Draws red outlines around individual character bounding boxes and green outlines around syllable boxes — useful for diagnosing layout issues |