diff --git a/app/src/main/kotlin/me/echeung/moemoekyun/client/api/Stream.kt b/app/src/main/kotlin/me/echeung/moemoekyun/client/api/Stream.kt index ecfd092f..8836cfb5 100644 --- a/app/src/main/kotlin/me/echeung/moemoekyun/client/api/Stream.kt +++ b/app/src/main/kotlin/me/echeung/moemoekyun/client/api/Stream.kt @@ -43,10 +43,15 @@ class Stream @Inject constructor( private val eventListener = object : Player.Listener { override fun onPlaybackStateChanged(playbackState: Int) { + logcat { "stream onPlaybackStateChanged: $playbackState" } if (playbackState == Player.STATE_BUFFERING) { _flow.value = State.BUFFERING - } else if (isPlaying && playbackState == Player.STATE_READY) { - _flow.value = State.PLAYING + } else if (playbackState == Player.STATE_READY) { + if (isPlaying) { + _flow.value = State.PLAYING + } else { + play() + } } else if (player?.playWhenReady == true) { _flow.value = State.PAUSED } diff --git a/app/src/main/kotlin/me/echeung/moemoekyun/domain/radio/RadioService.kt b/app/src/main/kotlin/me/echeung/moemoekyun/domain/radio/RadioService.kt index 1da99d5e..b536211a 100644 --- a/app/src/main/kotlin/me/echeung/moemoekyun/domain/radio/RadioService.kt +++ b/app/src/main/kotlin/me/echeung/moemoekyun/domain/radio/RadioService.kt @@ -87,6 +87,7 @@ class RadioService @Inject constructor( scope.launchIO { stream.flow .collectLatest { + logcat { "stream service flow: $it" } _state.value = _state.value.copy( streamState = it, ) @@ -127,10 +128,9 @@ class RadioService @Inject constructor( } fun togglePlayState() { - if (_state.value.streamState != Stream.State.PAUSED) { - stream.pause() - } else { - stream.play() + when (_state.value.streamState) { + Stream.State.PLAYING, Stream.State.BUFFERING -> stream.pause() + Stream.State.PAUSED, Stream.State.STOPPED -> stream.play() } }