Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ interface EpisodePlayer {
* Rewinds a currently played episode by a given time interval specified in [duration].
*/
fun rewindBy(duration: Duration)

/**
* Changes the speed of which the player increments
*/
fun changePlaySpeed(duration: Duration)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MockEpisodePlayer(
private val coroutineScope = CoroutineScope(mainDispatcher)

private var timerJob: Job? = null
private var playerSpeed: Duration = Duration.ofSeconds(1)

init {
coroutineScope.launch {
Expand Down Expand Up @@ -90,8 +91,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 Expand Up @@ -157,6 +158,10 @@ class MockEpisodePlayer(
}
}

override fun changePlaySpeed(duration: Duration) {
playerSpeed = duration
}

override fun next() {
val q = queue.value
if (q.isEmpty()) {
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.changePlaySpeed(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