This commit is contained in:
rang 2026-01-05 17:29:24 +08:00
parent 178f3fbdb1
commit 634ffaed8c
27 changed files with 648 additions and 1012 deletions

View file

@ -1,55 +1,55 @@
import 'dart:async';
// import 'dart:async';
import 'package:vaani/features/player/core/abs_audio_player.dart';
import 'package:vaani/shared/extensions/chapter.dart';
import 'package:vaani/shared/utils/throttler.dart';
// import 'package:vaani/features/player/core/abs_audio_player.dart';
// import 'package:vaani/shared/extensions/chapter.dart';
// import 'package:vaani/shared/utils/throttler.dart';
class SkipStartEnd {
final Duration start;
final Duration end;
final AbsAudioPlayer player;
// class SkipStartEnd {
// final Duration start;
// final Duration end;
// final AbsAudioPlayer player;
final List<StreamSubscription> _subscriptions = [];
final throttlerStart = Throttler(delay: Duration(seconds: 3));
final throttlerEnd = Throttler(delay: Duration(seconds: 3));
// final List<StreamSubscription> _subscriptions = [];
// final throttlerStart = Throttler(delay: Duration(seconds: 3));
// final throttlerEnd = Throttler(delay: Duration(seconds: 3));
SkipStartEnd({
required this.start,
required this.end,
required this.player,
}) {
if (start > Duration.zero) {
_subscriptions.add(
player.chapterStream.listen((chapter) async {
if (chapter != null &&
player.positionInChapter < Duration(seconds: 1)) {
player.seekInBook(chapter.start + start);
}
}),
);
}
if (end > Duration.zero) {
_subscriptions.add(
player.positionInChapterStream.listen((positionChapter) {
if (end >
(player.currentChapter?.duration ?? Duration.zero) -
positionChapter) {
Future.microtask(
() => throttlerEnd.call(() => player.next()),
);
}
}),
);
}
}
// SkipStartEnd({
// required this.start,
// required this.end,
// required this.player,
// }) {
// if (start > Duration.zero) {
// _subscriptions.add(
// player.chapterStream.listen((chapter) async {
// if (chapter != null &&
// player.positionInChapter < Duration(seconds: 1)) {
// player.seekInBook(chapter.start + start);
// }
// }),
// );
// }
// if (end > Duration.zero) {
// _subscriptions.add(
// player.positionInChapterStream.listen((positionChapter) {
// if (end >
// (player.currentChapter?.duration ?? Duration.zero) -
// positionChapter) {
// Future.microtask(
// () => throttlerEnd.call(() => player.next()),
// );
// }
// }),
// );
// }
// }
/// dispose the timer
void dispose() {
for (var sub in _subscriptions) {
sub.cancel();
}
throttlerStart.dispose();
throttlerEnd.dispose();
// _playbackController.close();
}
}
// /// dispose the timer
// void dispose() {
// for (var sub in _subscriptions) {
// sub.cancel();
// }
// throttlerStart.dispose();
// throttlerEnd.dispose();
// // _playbackController.close();
// }
// }