feature: add auto-pause playback feature

This commit is contained in:
Antoine Jaury
2026-08-04 21:29:27 +02:00
parent ff4ef71bfd
commit 23eb83490f
14 changed files with 104 additions and 11 deletions
@@ -186,11 +186,16 @@ internal class PlaybackRepositoryImpl(
}
/**
* Inserts the configured silent break between spoken phrases: when continuous playback reaches
* the next phrase, playback pauses just before that phrase starts, then resumes after the break.
* Reacts to reaching the next spoken phrase during continuous playback, just before that phrase
* starts. Depending on preferences it either:
* - pauses and waits for the user to resume, when auto-pause is enabled, or
* - pauses for the configured silent break and then resumes on its own.
*
* Breaks only happen on automatic advancement — manual seeking and previous/next navigation are
* ignored via [suppressBreaks].
* Auto-pause takes precedence: while it is on, the break between phrases is ignored.
*
* This only happens on automatic advancement — manual seeking and previous/next navigation are
* ignored because they cancel the running break job and never re-enter [PlaybackState.PLAYING]
* through this path.
*/
private suspend fun observePhraseBreaks() {
phraseBreakJob?.cancel()
@@ -203,6 +208,11 @@ internal class PlaybackRepositoryImpl(
if (playbackState.firstOrNull() != PlaybackState.PLAYING) return@onEach
val playbackPreferences = preferencesRepository.playbackPreferences.first()
if (playbackPreferences.autoPause) {
audioPlayer.pause()
return@onEach
}
val breakDuration = playbackPreferences.breakBetweenPhrases
if (breakDuration <= Duration.ZERO) return@onEach