Skip to content

Commit

Permalink
[Jetcaster] Add functionality to change the speed of the player (#1348)
Browse files Browse the repository at this point in the history
So that the player speed can be changed on Wear.
  • Loading branch information
arriolac authored Apr 18, 2024
2 parents 4a736b7 + 6ed8dfa commit 78f5df9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ interface EpisodePlayer {
*/
var currentEpisode: PlayerEpisode?

/**
* The speed of which the player increments
*/
var playerSpeed: Duration

fun addToQueue(episode: PlayerEpisode)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class MockEpisodePlayer(
}
}

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

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

override var currentEpisode: PlayerEpisode? by _currentEpisode
Expand All @@ -90,8 +92,8 @@ class MockEpisodePlayer(
timerJob = coroutineScope.launch {
// Increment timer by a second
while (isActive && timeElapsed.value < episode.duration) {
delay(1000L)
timeElapsed.update { it + Duration.ofSeconds(1) }
delay(playerSpeed.toMillis())
timeElapsed.update { it + playerSpeed }
}

// Once done playing, see if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ class MockEpisodePlayerTest {
),
)

@Test
fun whenPlay_incrementsByPlaySpeed() = runTest(testDispatcher) {
val playSpeed = Duration.ofSeconds(2)
val currEpisode = PlayerEpisode(
uri = "currentEpisode",
duration = Duration.ofSeconds(60)
)
mockEpisodePlayer.currentEpisode = currEpisode
mockEpisodePlayer.playerSpeed = playSpeed

mockEpisodePlayer.play()
advanceTimeBy(playSpeed.toMillis() + 300)

assertEquals(playSpeed, mockEpisodePlayer.playerState.value.timeElapsed)
}

@Test
fun whenPlayDone_playerAutoPlaysNextEpisode() = runTest(testDispatcher) {
val duration = Duration.ofSeconds(60)
Expand Down

0 comments on commit 78f5df9

Please sign in to comment.