From 4f06b8a0ff799528feb848680cbc3ceef2bcccb9 Mon Sep 17 00:00:00 2001 From: grakovne Date: Mon, 14 Oct 2024 23:06:00 +0200 Subject: [PATCH] polish --- .../grakovne/lissen/playback/service/PlaybackService.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/grakovne/lissen/playback/service/PlaybackService.kt b/app/src/main/java/org/grakovne/lissen/playback/service/PlaybackService.kt index 54c0fa73..aa316102 100644 --- a/app/src/main/java/org/grakovne/lissen/playback/service/PlaybackService.kt +++ b/app/src/main/java/org/grakovne/lissen/playback/service/PlaybackService.kt @@ -103,7 +103,6 @@ class AudioPlayerService : MediaSessionService() { private suspend fun preparePlayback(book: DetailedBook) { exoPlayer.playWhenReady = false - withContext(Dispatchers.IO) { async { playbackSynchronizationService.stopPlaybackSynchronization() }.await() val prepareQueue = async { @@ -163,10 +162,9 @@ class AudioPlayerService : MediaSessionService() { when (progress) { null -> exoPlayer.seekTo(0, 0) else -> { - val totalDuration = - chapters.runningFold(0.0) { acc, chapter -> acc + chapter.duration } - val targetChapter = totalDuration.indexOfFirst { it > progress.currentTime } - val chapterProgress = progress.currentTime - totalDuration[targetChapter - 1] + val duration = chapters.runningFold(0.0) { acc, chapter -> acc + chapter.duration } + val targetChapter = duration.indexOfFirst { it > progress.currentTime } + val chapterProgress = progress.currentTime - duration[targetChapter - 1] exoPlayer.seekTo(targetChapter - 1, (chapterProgress * 1000).toLong()) }