fix: handle buffering state in playback state management as playing
This commit is contained in:
+5
-1
@@ -24,15 +24,19 @@ internal class AndroidAudioPlayer(
|
|||||||
init {
|
init {
|
||||||
player.addListener(
|
player.addListener(
|
||||||
object : Player.Listener {
|
object : Player.Listener {
|
||||||
|
var isBuffering = false
|
||||||
|
|
||||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
if (playbackState == Player.STATE_ENDED) {
|
if (playbackState == Player.STATE_ENDED) {
|
||||||
_playbackState.value = PlaybackState.ENDED
|
_playbackState.value = PlaybackState.ENDED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBuffering = playbackState == Player.STATE_BUFFERING
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||||
_playbackState.value = when {
|
_playbackState.value = when {
|
||||||
isPlaying -> PlaybackState.PLAYING
|
isPlaying || isBuffering -> PlaybackState.PLAYING
|
||||||
player.playbackState == Player.STATE_ENDED -> PlaybackState.ENDED
|
player.playbackState == Player.STATE_ENDED -> PlaybackState.ENDED
|
||||||
else -> PlaybackState.PAUSED
|
else -> PlaybackState.PAUSED
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user