Refactor chapter seeking logic in AudiobookPlayerSeekChapterButton

This commit is contained in:
Dr-Blank 2024-05-20 07:45:06 -04:00
parent 2f078742d0
commit b2130a53cc
No known key found for this signature in database
GPG key ID: 7452CC63F210A266
6 changed files with 27 additions and 88 deletions

View file

@ -204,6 +204,22 @@ class AudiobookPlayer extends AudioPlayer {
});
}
/// a convenience getter for slow position stream
Stream<Duration> get slowPositionStream {
final superPositionStream = createPositionStream(
steps: 100,
minPeriod: const Duration(milliseconds: 500),
maxPeriod: const Duration(seconds: 1),
);
// now we need to map the position to the book instead of the current track
return superPositionStream.map((position) {
if (_book == null) {
return Duration.zero;
}
return position + _book!.tracks[sequenceState!.currentIndex].startOffset;
});
}
/// get current chapter
BookChapter? get currentChapter {
if (_book == null) {