mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-16 22:39:34 +00:00
修复章节列表滚动 在windows平台报错
This commit is contained in:
parent
620a1eb7a2
commit
05bc0cde74
7 changed files with 32 additions and 12 deletions
|
|
@ -174,12 +174,31 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @override
|
||||||
|
// Future<void> seek(Duration? positionInBook, {int? index, bool b = true}) async {
|
||||||
|
// if (!b) {
|
||||||
|
// return super.seek(positionInBook, index: index);
|
||||||
|
// }
|
||||||
|
// if (_book == null) {
|
||||||
|
// _logger.warning('No book is set, not seeking');
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// if (positionInBook == null) {
|
||||||
|
// _logger.warning('Position given is null, not seeking');
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// final tracks = _book!.tracks;
|
||||||
|
// final trackToPlay = getTrackToPlay(_book!, positionInBook);
|
||||||
|
// final i = tracks.indexOf(trackToPlay);
|
||||||
|
// final positionInTrack = positionInBook - trackToPlay.startOffset;
|
||||||
|
// return super.seek(positionInTrack, index: i);
|
||||||
|
// }
|
||||||
|
|
||||||
/// need to override getDuration and getCurrentPosition to return according to the book instead of the current track
|
/// need to override getDuration and getCurrentPosition to return according to the book instead of the current track
|
||||||
/// this is because the book can be a list of audio files and the player is only aware of the current track
|
/// this is because the book can be a list of audio files and the player is only aware of the current track
|
||||||
/// so we need to calculate the duration and current position based on the book
|
/// so we need to calculate the duration and current position based on the book
|
||||||
|
|
||||||
@override
|
Future<void> seekInBook(Duration? positionInBook, {int? index, bool b = true}) async {
|
||||||
Future<void> seek(Duration? positionInBook, {int? index, bool b = true}) async {
|
|
||||||
if (!b) {
|
if (!b) {
|
||||||
return super.seek(positionInBook, index: index);
|
return super.seek(positionInBook, index: index);
|
||||||
}
|
}
|
||||||
|
|
@ -208,11 +227,11 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
void seekForward() {
|
void seekForward() {
|
||||||
final index = _book!.chapters.indexOf(currentChapter!);
|
final index = _book!.chapters.indexOf(currentChapter!);
|
||||||
if (index < _book!.chapters.length - 1) {
|
if (index < _book!.chapters.length - 1) {
|
||||||
seek(
|
super.seek(
|
||||||
_book!.chapters[index + 1].start + offset,
|
_book!.chapters[index + 1].start + offset,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
seek(currentChapter!.end);
|
super.seek(currentChapter!.end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,7 +246,7 @@ class AudiobookPlayer extends AudioPlayer {
|
||||||
} else {
|
} else {
|
||||||
chapterToSeekTo = currentChapter!;
|
chapterToSeekTo = currentChapter!;
|
||||||
}
|
}
|
||||||
seek(
|
super.seek(
|
||||||
chapterToSeekTo.start + offset,
|
chapterToSeekTo.start + offset,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ class AudiobookPlayerPlayPauseButton extends HookConsumerWidget {
|
||||||
),
|
),
|
||||||
ProcessingState.completed => IconButton(
|
ProcessingState.completed => IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await player.seek(const Duration(seconds: 0));
|
await player.seekInBook(const Duration(seconds: 0));
|
||||||
await player.play();
|
await player.play();
|
||||||
},
|
},
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
|
|
@ -220,7 +220,7 @@ class AudiobookChapterProgressBar extends HookConsumerWidget {
|
||||||
: currentChapter.end - currentChapter.start,
|
: currentChapter.end - currentChapter.start,
|
||||||
// ! TODO add onSeek
|
// ! TODO add onSeek
|
||||||
onSeek: (duration) {
|
onSeek: (duration) {
|
||||||
player.seek(
|
player.seekInBook(
|
||||||
duration + (currentChapter?.start ?? const Duration(seconds: 0)),
|
duration + (currentChapter?.start ?? const Duration(seconds: 0)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,7 @@ class PlayerWhenExpanded extends HookConsumerWidget {
|
||||||
|
|
||||||
// the chapter skip buttons, seek 30 seconds back and forward, and play/pause button
|
// the chapter skip buttons, seek 30 seconds back and forward, and play/pause button
|
||||||
Expanded(
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: earlyPercentage,
|
opacity: earlyPercentage,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ class AudiobookPlayerSeekButton extends HookConsumerWidget {
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (isForward) {
|
if (isForward) {
|
||||||
player.seek(player.positionInBook + const Duration(seconds: 30));
|
player.seek(player.position + const Duration(seconds: 30));
|
||||||
} else {
|
} else {
|
||||||
player.seek(player.positionInBook - const Duration(seconds: 30));
|
player.seek(player.position - const Duration(seconds: 30));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class AudiobookPlayerSeekChapterButton extends HookConsumerWidget {
|
||||||
}
|
}
|
||||||
// if chapter does not exist, go to the start or end of the book
|
// if chapter does not exist, go to the start or end of the book
|
||||||
if (player.currentChapter == null) {
|
if (player.currentChapter == null) {
|
||||||
player.seek(isForward ? player.book!.duration : Duration.zero);
|
player.seekInBook(isForward ? player.book!.duration : Duration.zero);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isForward) {
|
if (isForward) {
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ class ChapterSelectionModal extends HookConsumerWidget {
|
||||||
key: isCurrent ? chapterKey : null,
|
key: isCurrent ? chapterKey : null,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
notifier.seek(chapter.start + 90.ms);
|
notifier.seekInBook(chapter.start + 90.ms);
|
||||||
notifier.play();
|
notifier.play();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class SkipStartEnd {
|
||||||
if (_index != index && player.position.inMilliseconds < 500) {
|
if (_index != index && player.position.inMilliseconds < 500) {
|
||||||
_index = index!;
|
_index = index!;
|
||||||
Future.microtask(() {
|
Future.microtask(() {
|
||||||
player.seek(start, b: false);
|
player.seek(start);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue