Skip to content

Commit 7c08d29

Browse files
authored
Fix audiobook locators' total progression (#553)
1 parent 9a42145 commit 7c08d29

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file. Take a look
44

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

7-
<!-- ## [Unreleased] -->
7+
## [Unreleased]
8+
9+
### Fixed
10+
11+
#### Navigator
12+
13+
* Fixed computing the total progression of audiobook locators.
14+
815

916
## [3.0.0-beta.2]
1017

readium/navigators/media/audio/src/main/java/org/readium/navigator/media/audio/AudioNavigator.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ public class AudioNavigator<S : Configurable.Settings, P : Configurable.Preferen
9090
val currentItem = readingOrder.items[playback.index]
9191
val link = requireNotNull(publication.linkWithHref(currentItem.href))
9292
val item = readingOrder.items[playback.index]
93-
val itemStartPosition = readingOrder.items
94-
.slice(0 until playback.index)
95-
.mapNotNull { it.duration }
96-
.takeIf { it.size == readingOrder.items.size }
97-
?.sum()
93+
val itemStartPosition =
94+
readingOrder.items
95+
.takeIf { readingOrderHasDuration }
96+
?.slice(0 until playback.index)
97+
?.mapNotNull { it.duration }
98+
?.sum()
9899

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

118+
private val readingOrderHasDuration: Boolean =
119+
readingOrder.items.all { it.duration != null }
120+
117121
override val playback: StateFlow<Playback> =
118122
audioEngine.playback.mapStateIn(coroutineScope) { playback ->
119123
val itemDuration =

0 commit comments

Comments
 (0)