This commit is contained in:
rang 2025-12-10 17:21:59 +08:00
parent 4a7c592e41
commit 36f14dbd58
4 changed files with 18 additions and 10 deletions

View file

@ -48,9 +48,11 @@ class AbsAudioHandler extends BaseAudioHandler with QueueHandler, SeekHandler {
});
// 2.
player.positionStream.listen((Duration position) {
playbackState.add(playbackState.value.copyWith(
updatePosition: position,
));
playbackState.add(
playbackState.value.copyWith(
updatePosition: position,
),
);
});
// 3.
// player.stream.duration.listen((Duration? duration) {

View file

@ -2,6 +2,7 @@ import 'package:just_audio/just_audio.dart';
import 'package:just_audio_media_kit/just_audio_media_kit.dart';
import 'package:logging/logging.dart';
import 'package:vaani/features/player/core/abs_audio_player.dart';
import 'package:vaani/shared/extensions/chapter.dart';
final _logger = Logger('AbsPlatformAudioPlayer');
@ -9,6 +10,13 @@ final _logger = Logger('AbsPlatformAudioPlayer');
class AbsPlatformAudioPlayer extends AbsAudioPlayer {
late final AudioPlayer player;
AbsPlatformAudioPlayer() {
//
// prefetch-playlist=yes
JustAudioMediaKit.prefetchPlaylist = true;
// merge-files=yes
// cache=yes
// cache-pause-wait=60
JustAudioMediaKit.ensureInitialized();
player = AudioPlayer();
player.playerStateStream.listen((state) {
@ -31,6 +39,9 @@ class AbsPlatformAudioPlayer extends AbsAudioPlayer {
positionInBook <= (chapter?.end ?? Duration.zero)) {
final chapter = book?.findChapterAtTime(positionInBook);
if (chapter != currentChapter) {
print('当前章节时长: ${currentChapter?.duration}');
print('切换章节时长: ${chapter?.duration}');
print('当前播放音轨时长: ${player.duration}');
chapterStreamController.add(chapter);
}
}

View file

@ -20,16 +20,10 @@ class SkipStartEnd {
}) {
if (start > Duration.zero) {
_subscriptions.add(
player.chapterStream.listen((chapter) {
player.chapterStream.listen((chapter) async {
if (chapter != null &&
player.positionInChapter < Duration(seconds: 1)) {
// player.pause();
player.seekInBook(chapter.start + start);
// player.play();
// Future.microtask(
// () => throttlerStart
// .call(() => player.seekInBook(chapter.start + start)),
// );
}
}),
);