Skip to content

Instantly share code, notes, and snippets.

@micHar
Created June 20, 2022 13:17
Show Gist options
  • Save micHar/3742a2f7d94b6f97da7fb60d88c949df to your computer and use it in GitHub Desktop.
Save micHar/3742a2f7d94b6f97da7fb60d88c949df to your computer and use it in GitHub Desktop.
interface SoundPlayer {
suspend fun playSound()
}
sealed class PlayerState {
object Stopped : PlayerState()
object Playing : PlayerState()
}
class MediaPlayer(
private val scope: CoroutineScope,
private val soundPlayer: SoundPlayer
) {
val playerState = MutableStateFlow<PlayerState>(PlayerState.Stopped)
fun play() {
scope.launch {
playerState.emit(PlayerState.Playing)
soundPlayer.playSound()
playerState.emit(PlayerState.Stopped)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment