mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-21 02:19:30 +00:00
Refactor chapter seeking logic in AudiobookPlayerSeekChapterButton
This commit is contained in:
parent
74dc9807d6
commit
2f078742d0
1 changed files with 20 additions and 3 deletions
|
|
@ -311,7 +311,19 @@ class AudiobookPlayerSeekChapterButton extends HookConsumerWidget {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isForward) {
|
if (isForward) {
|
||||||
|
// instead of seeking to the end of the chapter, go to the next chapter start
|
||||||
|
// player.seek(player.currentChapter!.end);
|
||||||
|
final index = player.book!.chapters.indexOf(player.currentChapter!);
|
||||||
|
if (index < player.book!.chapters.length - 1) {
|
||||||
|
player.seek(
|
||||||
|
player.book!.chapters[index + 1].start +
|
||||||
|
const Duration(
|
||||||
|
microseconds: 50,
|
||||||
|
), // add a small offset so the display does not show the previous chapter for a split second
|
||||||
|
);
|
||||||
|
} else {
|
||||||
player.seek(player.currentChapter!.end);
|
player.seek(player.currentChapter!.end);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// if player position is less than 5 seconds into the chapter, go to the previous chapter
|
// if player position is less than 5 seconds into the chapter, go to the previous chapter
|
||||||
final chapterPosition =
|
final chapterPosition =
|
||||||
|
|
@ -319,10 +331,15 @@ class AudiobookPlayerSeekChapterButton extends HookConsumerWidget {
|
||||||
if (chapterPosition < const Duration(seconds: 5)) {
|
if (chapterPosition < const Duration(seconds: 5)) {
|
||||||
final index = player.book!.chapters.indexOf(player.currentChapter!);
|
final index = player.book!.chapters.indexOf(player.currentChapter!);
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
player.seek(player.book!.chapters[index - 1].start);
|
player.seek(
|
||||||
|
player.book!.chapters[index - 1].start +
|
||||||
|
const Duration(microseconds: 50),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.seek(player.currentChapter!.start);
|
player.seek(
|
||||||
|
player.currentChapter!.start + const Duration(microseconds: 50),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue