Skip to content

Commit

Permalink
[Jetcaster]: Make player speed part of EpisodePlayerState (#1356)
Browse files Browse the repository at this point in the history
So that the player speed can be reflected on the UI as it changes.So
that the player speed can be reflected on the UI as it changes.So that
the player speed can be reflected on the UI as it changes.
  • Loading branch information
arriolac committed Apr 22, 2024
2 parents 08138cd + 16a767b commit 0bfe3ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import com.example.jetcaster.core.model.PlayerEpisode
import java.time.Duration
import kotlinx.coroutines.flow.StateFlow

val DefaultPlaybackSpeed = Duration.ofSeconds(1)
data class EpisodePlayerState(
val currentEpisode: PlayerEpisode? = null,
val queue: List<PlayerEpisode> = emptyList(),
val playbackSpeed: Duration = DefaultPlaybackSpeed,
val isPlaying: Boolean = false,
val timeElapsed: Duration = Duration.ZERO,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MockEpisodePlayer(
private val queue = MutableStateFlow<List<PlayerEpisode>>(emptyList())
private val isPlaying = MutableStateFlow(false)
private val timeElapsed = MutableStateFlow(Duration.ZERO)
private val _playerSpeed = MutableStateFlow(DefaultPlaybackSpeed)
private val coroutineScope = CoroutineScope(mainDispatcher)

private var timerJob: Job? = null
Expand All @@ -52,13 +53,15 @@ class MockEpisodePlayer(
_currentEpisode,
queue,
isPlaying,
timeElapsed
) { currentEpisode, queue, isPlaying, timeElapsed ->
timeElapsed,
_playerSpeed
) { currentEpisode, queue, isPlaying, timeElapsed, playerSpeed ->
EpisodePlayerState(
currentEpisode = currentEpisode,
queue = queue,
isPlaying = isPlaying,
timeElapsed = timeElapsed
timeElapsed = timeElapsed,
playbackSpeed = playerSpeed
)
}.catch {
// TODO handle error state
Expand All @@ -69,7 +72,7 @@ class MockEpisodePlayer(
}
}

override var playerSpeed: Duration = Duration.ofSeconds(1)
override var playerSpeed: Duration = _playerSpeed.value

override val playerState: StateFlow<EpisodePlayerState> = _playerState.asStateFlow()

Expand Down

0 comments on commit 0bfe3ae

Please sign in to comment.