### LyricsViewState Playback Controls with Kotlin Source: https://context7.com/dokar3/amlv/llms.txt Manages lyrics playback, including position tracking, play/pause functionality, and seeking. It automatically updates the current line index based on the playback position. This example demonstrates a Composable function for full playback controls. ```kotlin import com.dokar.amlv.LyricsViewState import com.dokar.amlv.rememberLyricsViewState @Composable fun FullPlaybackControls() { val state = rememberLyricsViewState(lrcContent = lrcContent) Column { // Play/Pause toggle IconButton(onClick = { if (state.isPlaying) { state.pause() } else { state.play() } }) { Icon( imageVector = if (state.isPlaying) Icons.Filled.Pause else Icons.Filled.PlayArrow, contentDescription = "Play/Pause" ) } // Seek slider val duration = state.lyrics?.optimalDurationMillis ?: 1L Slider( value = state.position.toFloat() / duration, onValueChange = { state.seekTo((duration * progress).toLong()) } ) // Seek to specific line (tapping a lyric line) state.lyrics?.lines?.forEachIndexed { index, line -> Text( text = line.content, modifier = Modifier.clickable { state.seekToLine(index) } ) } } } ``` -------------------------------- ### FadingEdges for Edge Fade Effects with Kotlin Source: https://context7.com/dokar3/amlv/llms.txt Configures gradient fading effects on the edges of the lyrics view to create a polished visual transition at the boundaries. This example shows how to use `FadingEdges` with `LyricsView` for no fades, custom fades on all sides, and typical top/bottom fades. ```kotlin import com.dokar.amlv.FadingEdges import com.dokar.amlv.LyricsView import androidx.compose.ui.unit.dp @Composable fun LyricsWithFadingEdges() { val state = rememberLyricsViewState(lrcContent = lrcContent) // No fading edges LyricsView( state = state, fadingEdges = FadingEdges.None ) // Custom fading edges on all sides LyricsView( state = state, fadingEdges = FadingEdges( start = 0.dp, top = 32.dp, end = 0.dp, bottom = 100.dp ) ) // Typical usage with top and bottom fades LyricsView( state = state, fadingEdges = FadingEdges(top = 16.dp, bottom = 150.dp), contentPadding = PaddingValues(bottom = 150.dp) ) } ``` -------------------------------- ### LrcLyricsParser for Parsing LRC Files with Kotlin Source: https://context7.com/dokar3/amlv/llms.txt A parser implementation for standard LRC (LyRC) format files. It extracts metadata such as title, artist, album, and duration, along with timed lyric lines. The example shows how to parse LRC content and access the extracted information. ```kotlin import com.dokar.amlv.parser.LrcLyricsParser // Parse LRC content manually val parser = LrcLyricsParser() val lrcContent = """ [ar:Pink Floyd] [ti:Time] [al:The Dark Side of the Moon] [length:06:53.00] [00:00.00]Ticking away the moments that make up a dull day [00:07.38]Fritter and waste the hours in an offhand way [00:14.59]Kicking around on a piece of ground in your hometown [00:21.82]Waiting for someone or something to show you the way """.trimIndent() val lyrics: Lyrics? = parser.parse(lrcContent) lyrics?.let { println("Title: ${it.title}") // Output: Title: Time println("Artist: ${it.artist}") // Output: Artist: Pink Floyd println("Album: ${it.album}") // Output: Album: The Dark Side of the Moon println("Duration: ${it.durationMillis}ms") // Output: Duration: 413000ms println("Lines: ${it.lines.size}") // Output: Lines: 4 // Each line contains: it.lines.forEach { line -> println("${line.startAt}ms: ${line.content} (${line.durationMillis}ms)") } } ``` -------------------------------- ### Lyrics Data Class for Representing Parsed Lyrics with Kotlin Source: https://context7.com/dokar3/amlv/llms.txt An immutable data class that represents parsed lyrics, including metadata and timed lines. It enforces that lines must have non-negative `startAt` and `durationMillis` values. The example demonstrates creating lyrics programmatically and accessing the `optimalDurationMillis`. ```kotlin import com.dokar.amlv.Lyrics // Create lyrics programmatically val lyrics = Lyrics( title = "Custom Song", artist = "Custom Artist", album = "Custom Album", durationMillis = 240000L, lines = listOf( Lyrics.Line( content = "Opening line of the song", startAt = 0L, durationMillis = 4000L ), Lyrics.Line( content = "The verse continues here", startAt = 4000L, durationMillis = 4500L ), Lyrics.Line( content = "Building up to the chorus", startAt = 8500L, durationMillis = 3500L ) ) ) // Access optimal duration (uses provided duration or calculates from lines) val totalDuration = lyrics.optimalDurationMillis ``` -------------------------------- ### Complete Music Player Integration with AMLV (Kotlin) Source: https://context7.com/dokar3/amlv/llms.txt This Kotlin code demonstrates a full integration of the AMLV library into a Jetpack Compose music player. It includes setting up the lyrics state, rendering the lyrics view with customizable styling, and implementing playback controls with a progress slider. Dependencies include Jetpack Compose UI, Material 3, and the AMLV library. ```kotlin import com.dokar.amlv.* import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @Composable fun CompleteMusicPlayer() { val lrcContent = """ [ar:The Beatles] [ti:Help!] [al:Help!] [length:02:19.23] [00:01.00]Help! I need somebody [00:02.91]Help! Not just anybody [00:05.16]Help! You know I need someone [00:07.91]Help! """.trimIndent() val state = rememberLyricsViewState(lrcContent = lrcContent) Column( modifier = Modifier .fillMaxSize() .background(Color.Black) .systemBarsPadding() ) { // Title bar Column(modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp)) { Text( text = state.lyrics?.title ?: "", color = Color.White, fontSize = 20.sp, fontWeight = FontWeight.Bold ) state.lyrics?.artist?.let { artist -> Text( text = artist, color = Color.White.copy(alpha = 0.7f), fontSize = 18.sp ) } } // Lyrics view LyricsView( state = state, modifier = Modifier.weight(1f), contentPadding = PaddingValues(16.dp), darkTheme = true, fadingEdges = FadingEdges(top = 16.dp, bottom = 150.dp), fontSize = 32.sp, fontWeight = FontWeight.Bold ) // Playback controls Column(modifier = Modifier.padding(32.dp)) { val duration = state.lyrics?.optimalDurationMillis ?: 1L var progress by remember { mutableFloatStateOf(0f) } LaunchedEffect(state) { snapshotFlow { state.position } .collect { progress = it.toFloat() / duration } } Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) { Text(formatTime(state.position), color = Color.White, fontSize = 14.sp) Text(formatTime(duration), color = Color.White, fontSize = 14.sp) } Slider( value = progress, onValueChange = { state.seekTo((duration * it).toLong()) }, colors = SliderDefaults.colors( thumbColor = Color.White, activeTrackColor = Color.White.copy(alpha = 0.8f), inactiveTrackColor = Color.White.copy(alpha = 0.5f) ) ) Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center ) { IconButton( onClick = { if (state.isPlaying) state.pause() else state.play() }, modifier = Modifier.size(56.dp) ) { Icon( imageVector = if (state.isPlaying) Icons.Filled.Pause else Icons.Filled.PlayArrow, contentDescription = "Play/Pause", tint = Color.White, modifier = Modifier.size(48.dp) ) } } } } } private fun formatTime(millis: Long): String { val minutes = millis / 1000 / 60 val seconds = (millis - minutes * 60 * 1000) / 1000 return "$minutes:${String.format("%02d", seconds)}" } ``` -------------------------------- ### Manage Lyrics State from Lyrics Object (Kotlin) Source: https://context7.com/dokar3/amlv/llms.txt Creates a LyricsViewState from a pre-constructed Lyrics object, enabling programmatic control over lyrics data. This is useful when lyrics are not loaded from an LRC file but generated or fetched otherwise. Dependencies include Jetpack Compose UI and the AMLV library. ```kotlin import com.dokar.amlv.Lyrics import com.dokar.amlv.rememberLyricsViewState @Composable fun CustomLyricsPlayer() { val lyrics = Lyrics( title = "My Song", artist = "My Artist", album = "My Album", durationMillis = 180000L, // 3 minutes lines = listOf( Lyrics.Line(content = "First verse line", startAt = 5000L, durationMillis = 5000L), Lyrics.Line(content = "Second verse line", startAt = 10000L, durationMillis = 5500L), Lyrics.Line(content = "Chorus begins here", startAt = 15500L, durationMillis = 6000L), Lyrics.Line(content = "Chorus continues", startAt = 21500L, durationMillis = 4500L) ) ) val state = rememberLyricsViewState(lyrics = lyrics) LyricsView(state = state, darkTheme = true) } ``` -------------------------------- ### Manage Lyrics State from LRC String (Kotlin) Source: https://context7.com/dokar3/amlv/llms.txt Creates and remembers a LyricsViewState by parsing an LRC-formatted string. This state manages playback position, current line, and play/pause status. It allows accessing lyrics metadata and controlling playback. Dependencies include Jetpack Compose UI and the AMLV library. ```kotlin import com.dokar.amlv.rememberLyricsViewState @Composable fun LyricsPlayer() { val lrcContent = """ [ar:The Beatles] [ti:Help!] [al:Help!] [length:02:19.23] [00:01.00]Help! I need somebody [00:02.91]Help! Not just anybody [00:05.16]Help! You know I need someone [00:07.91]Help! [00:10.66]When I was younger so much younger than today """.trimIndent() val state = rememberLyricsViewState(lrcContent = lrcContent) // Access lyrics metadata Text("Now Playing: ${state.lyrics?.title} by ${state.lyrics?.artist}") Text("Album: ${state.lyrics?.album}") Text("Duration: ${state.lyrics?.optimalDurationMillis}ms") // Playback controls Button(onClick = { state.play() }) { Text("Play") } Button(onClick = { state.pause() }) { Text("Pause") } // Current state Text("Position: ${state.position}ms") Text("Is Playing: ${state.isPlaying}") LyricsView(state = state) } ``` -------------------------------- ### Render Synchronized Lyrics with Animations (Kotlin) Source: https://context7.com/dokar3/amlv/llms.txt Displays synchronized lyrics with animations using the LyricsView composable. It takes a LyricsViewState and applies styling, fading edges, and padding. Dependencies include Jetpack Compose UI and the AMLV library. ```kotlin import com.dokar.amlv.FadingEdges import com.dokar.amlv.LyricsView import com.dokar.amlv.rememberLyricsViewState import androidx.compose.foundation.layout.PaddingValues import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.text.font.FontWeight @Composable fun MusicPlayerScreen() { val lrcContent = """ [ar:Artist Name] [ti:Song Title] [al:Album Name] [length:03:45.00] [00:05.00]First line of lyrics [00:10.50]Second line of lyrics [00:15.75]Third line of lyrics """.trimIndent() val state = rememberLyricsViewState(lrcContent = lrcContent) LyricsView( state = state, modifier = Modifier.fillMaxSize(), contentPadding = PaddingValues( start = 16.dp, top = 16.dp, end = 16.dp, bottom = 150.dp ), darkTheme = true, fadingEdges = FadingEdges(top = 16.dp, bottom = 150.dp), fontSize = 32.sp, fontWeight = FontWeight.Bold, lineHeight = 1.2.em ) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.