I'm trying to make UI for a media3 player but I'm ...
# compose
z
I'm trying to make UI for a media3 player but I'm not sure how to make the player variables like duration into states that cause recomposition
c
This highly depends on how you handle your state in general. Is is i.e just
rememberState
in the composeabe or maybe a view model?
s
In my short experience,
duration
and
currentPosition
are best handled using a
Handler
in loop: https://github.com/vfsfitvnm/ViMusic/blob/master/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/PlayerState.kt#L84
z
I think that'll work for me. @ste you're the dev behind ViMusic? do you think you could help me implement a miniplayer similar to how you did it in ViMusic. I've been trying to make one in an app I'm developing
f
If you’re going to adopt ste’s solution. You’d better consider adding a
dispose
function for removing the callback from the
Handler
when
PlayState
is no longer used. Or
Handler
will cause leaking.
1
z
I'm gonna use the listener solution you showed
f
What about using my library directly? 😀
s
Feng is right. I just added a
dispose
function accordingly
👍🏻 1
z
Maybe theres an event to listen to for when the media changes, so a handler wouldn't be necessary?
s
No, if you want to obtain the
currentPosition
, you must poll it. You can either use a
Handler
or whatever you like - e.g. you could also poll it within the
rememeberPlayerState
using
produceState