Created
June 20, 2022 13:17
-
-
Save micHar/3742a2f7d94b6f97da7fb60d88c949df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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