Skip to content

Commit 0bfe3ae

Browse files
authored
[Jetcaster]: Make player speed part of EpisodePlayerState (#1356)
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.
2 parents 08138cd + 16a767b commit 0bfe3ae

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Jetcaster/core/src/main/java/com/example/jetcaster/core/player/EpisodePlayer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import com.example.jetcaster.core.model.PlayerEpisode
2020
import java.time.Duration
2121
import kotlinx.coroutines.flow.StateFlow
2222

23+
val DefaultPlaybackSpeed = Duration.ofSeconds(1)
2324
data class EpisodePlayerState(
2425
val currentEpisode: PlayerEpisode? = null,
2526
val queue: List<PlayerEpisode> = emptyList(),
27+
val playbackSpeed: Duration = DefaultPlaybackSpeed,
2628
val isPlaying: Boolean = false,
2729
val timeElapsed: Duration = Duration.ZERO,
2830
)

Jetcaster/core/src/main/java/com/example/jetcaster/core/player/MockEpisodePlayer.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MockEpisodePlayer(
4141
private val queue = MutableStateFlow<List<PlayerEpisode>>(emptyList())
4242
private val isPlaying = MutableStateFlow(false)
4343
private val timeElapsed = MutableStateFlow(Duration.ZERO)
44+
private val _playerSpeed = MutableStateFlow(DefaultPlaybackSpeed)
4445
private val coroutineScope = CoroutineScope(mainDispatcher)
4546

4647
private var timerJob: Job? = null
@@ -52,13 +53,15 @@ class MockEpisodePlayer(
5253
_currentEpisode,
5354
queue,
5455
isPlaying,
55-
timeElapsed
56-
) { currentEpisode, queue, isPlaying, timeElapsed ->
56+
timeElapsed,
57+
_playerSpeed
58+
) { currentEpisode, queue, isPlaying, timeElapsed, playerSpeed ->
5759
EpisodePlayerState(
5860
currentEpisode = currentEpisode,
5961
queue = queue,
6062
isPlaying = isPlaying,
61-
timeElapsed = timeElapsed
63+
timeElapsed = timeElapsed,
64+
playbackSpeed = playerSpeed
6265
)
6366
}.catch {
6467
// TODO handle error state
@@ -69,7 +72,7 @@ class MockEpisodePlayer(
6972
}
7073
}
7174

72-
override var playerSpeed: Duration = Duration.ofSeconds(1)
75+
override var playerSpeed: Duration = _playerSpeed.value
7376

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

0 commit comments

Comments
 (0)