Last active
June 21, 2022 07:00
-
-
Save micHar/d6120f6dc33693fb7ebd10e76505b611 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() | |
} | |
class MediaPlayer( | |
private val scope: CoroutineScope, | |
private val soundPlayer: SoundPlayer | |
) { | |
val playerErrors = MutableSharedFlow<Exception>() | |
fun play() { | |
scope.launch { | |
try { | |
soundPlayer.playSound() | |
} catch (e: Exception) { | |
playerErrors.emit(e) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment