Last active
August 3, 2020 08:28
-
-
Save halilozercan/137f2f2d881b5f89c3fd5c2ab7febf50 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
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