I'm running in a kind-of state problem. I have an ...
# compose
p
I'm running in a kind-of state problem. I have an audiobook player. On the playback screen I show a Slider with the current position in the chapter. The backing state periodically emits with the current position. So for the slider value, I can't just use remember, else while playing, the track would not be updated. Instead I have passed the current time as the key to the remember function. In theory this works. However when you try to seek while on playback, the slider continues to be updated which causes visual glitches. Any idea how I can come around that? Here is my current implementation: https://github.com/PaulWoitaschek/Voice/blob/aad9fd7eafe734e739b7e20e4d908f242a95ce51/playbackScreen/src/main/java/voice/playbackScreen/views/PlaybackSlider.kt
z
So you would have to distinguish the source from where updates are coming from as they have different priorities. This should be done in the VM layer not the View itself tho. Basically when you touch the slider you ignore playback updates for this UI component.
r
I guess one followup question would be what is driving the periodic slider updates?
k
I did it in the UI layer with something like this
Copy code
var isTouching by remember { mutableStateOf(false) }  // if you use slider you can observe this by InteractionSource
var sliderValue by remember { mutableStateOf(player.position) }
LaunchedEffect(player.position) {
    if (!isTouching) sliderValue = player.position
}