Skip to content

Instantly share code, notes, and snippets.

@Qw4z1
Qw4z1 / Waveform.kt
Created July 13, 2024 07:20
Simple animated audio waveform meant to place in a player. RowScope is specific to my current use case to import the correct weight function.
@Composable
fun RowScope.WaveForm(progress: List<Float>) {
// State to track the horizontal offset for the animation
var offsetState by remember { mutableStateOf(0f) }
val itemWidth = with(LocalDensity.current) { 4.dp.toPx() }
val padding = with(LocalDensity.current) { 1.dp.toPx() }
// Animate the offset change
val animatedOffset by animateFloatAsState(
targetValue = offsetState,
animationSpec = tween(
package se.sabumbi.vacapp.audio
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow