What whould be the correct approach to play sound ...
# compose
p
What whould be the correct approach to play sound effects in Compose? should I have a val
activeSoundEffectFilePath: String?
in my
UiState
and set it to a path when a sound effect must be played and make a call to some viewmodel
fun playAudio(path: String)
when the Screen sees that the uistate constains that variable different from null? As this is audio, I'm not sure, and can't find any official link about this. If my approach is the correct one, where should be managed the logic for playing the sound effect? If the app haves various screens, each one with his own viewmodel... must the app have a "global" viewmodel that must receive these kind of global stuff like sound effects and manage them? that global viewmodel whould coexist with screens viewmodels, is that correct? if not... is not a better option to have a simple singleton "SoundEffectsManager" that triggers sounds and call it on the composables? without involving viewmodels
Well, first I tryed placing the logic in a usecase, injecting it in the viewmodel, and hosting and passing sound effects everywhere until they reached the viewmodel and that become a maze, so finally I reverted all and simply created a SoundEffectsManager singleton, which I'm calling on the composables with their parametrized sound effect
very simple, I think it's better, but I prefeer to wait until I read your opinions