I need to trigger a fake event to process the current progress with a flow and update the UI.
I've got following function which belongs to ViewModel A:
val listener = object : Player.Listener {
override fun onEvents(player: Player, events: Player.Events) {
trySend(player.toPlayerState())
.onFailure { Timber.w(it, "Error sending player state") }
super.onEvents(player, events)
}
}
This listener gets called on every event from the player (mediaController). All right!
I've got a second ViewModel (ViewModel B) which reseaves a message from the UI progress bar:
binding.playerControlView.setProgressUpdateListener { position, _ ->
viewModel.onUpdateProgress(position)
}
If the onUpdateProgress
function calls eg. the function to increase the sound, the event listener gets triggered. All right!
My goal is to trigger the event listener without changing anything (kind of fake trigger).
This is the code which should trigger the event listener:
fun onUpdateProgress(position: Long) {
viewModelScope.launch {
Timber.d("YYYYYY $position")
val player = getMediaController() // Returns Deferred<MediaController>
player.todo() // Replace by correct function
}
}
Maybe there is also a better approach to update the progress UI in ViewModel A?