Skip to content

Fix audiobook locators' total progression #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file. Take a look

**Warning:** Features marked as *experimental* may change or be removed in a future release without notice. Use with caution.

<!-- ## [Unreleased] -->
## [Unreleased]

### Fixed

#### Navigator

* Fixed computing the total progression of audiobook locators.


## [3.0.0-beta.2]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ public class AudioNavigator<S : Configurable.Settings, P : Configurable.Preferen
val currentItem = readingOrder.items[playback.index]
val link = requireNotNull(publication.linkWithHref(currentItem.href))
val item = readingOrder.items[playback.index]
val itemStartPosition = readingOrder.items
.slice(0 until playback.index)
.mapNotNull { it.duration }
.takeIf { it.size == readingOrder.items.size }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always failed because of the slice() above. We only have a portion of the reading order.

?.sum()
val itemStartPosition =
readingOrder.items
.takeIf { readingOrderHasDuration }
?.slice(0 until playback.index)
?.mapNotNull { it.duration }
?.sum()

val coercedOffset =
playback.coerceOffset(currentItem.duration)
Expand All @@ -114,6 +115,9 @@ public class AudioNavigator<S : Configurable.Settings, P : Configurable.Preferen
)
}

private val readingOrderHasDuration: Boolean =
readingOrder.items.all { it.duration != null }

override val playback: StateFlow<Playback> =
audioEngine.playback.mapStateIn(coroutineScope) { playback ->
val itemDuration =
Expand Down
Loading