Skip to content

Instantly share code, notes, and snippets.

@micHar
Last active June 21, 2022 07:00
Show Gist options
  • Save micHar/d6120f6dc33693fb7ebd10e76505b611 to your computer and use it in GitHub Desktop.
Save micHar/d6120f6dc33693fb7ebd10e76505b611 to your computer and use it in GitHub Desktop.
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