Skip to content

Instantly share code, notes, and snippets.

@halilozercan
Last active August 3, 2020 08:28
Show Gist options
  • Save halilozercan/137f2f2d881b5f89c3fd5c2ab7febf50 to your computer and use it in GitHub Desktop.
Save halilozercan/137f2f2d881b5f89c3fd5c2ab7febf50 to your computer and use it in GitHub Desktop.
private val _isPlaying = MutableStateFlow(true)
val isPlaying: StateFlow<Boolean> = _isPlaying
private val _playbackState = MutableStateFlow(ExoPlayer.STATE_IDLE)
val playbackState: StateFlow<Int> = _playbackState
private val exoPlayer by lazy {
SimpleExoPlayer.Builder(context).build().apply {
addListener(object: Player.EventListener {
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
super.onPlayerStateChanged(playWhenReady, playbackState)
_playbackState.value = playbackState
_isPlaying.value = playWhenReady
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment