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();
// }
// }

View file

@ -1,34 +1,34 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:vaani/features/per_book_settings/providers/book_settings_provider.dart';
import 'package:vaani/features/player/providers/abs_provider.dart';
import 'package:vaani/features/skip_start_end/core/skip_start_end.dart' as core;
// import 'package:riverpod_annotation/riverpod_annotation.dart';
// import 'package:vaani/features/per_book_settings/providers/book_settings_provider.dart';
// import 'package:vaani/features/player/providers/abs_provider.dart';
// import 'package:vaani/features/skip_start_end/core/skip_start_end.dart' as core;
part 'skip_start_end_provider.g.dart';
// part 'skip_start_end_provider.g.dart';
@riverpod
class SkipStartEnd extends _$SkipStartEnd {
@override
core.SkipStartEnd? build() {
final currentBook = ref.watch(currentBookProvider);
final bookId = currentBook?.libraryItemId;
if (currentBook == null || bookId == null) {
return null;
}
// @riverpod
// class SkipStartEnd extends _$SkipStartEnd {
// @override
// core.SkipStartEnd? build() {
// final currentBook = ref.watch(currentBookProvider);
// final bookId = currentBook?.libraryItemId;
// if (currentBook == null || bookId == null) {
// return null;
// }
final player = ref.read(absPlayerProvider);
final bookSettings = ref.watch(bookSettingsProvider(bookId));
final start = bookSettings.playerSettings.skipChapterStart;
final end = bookSettings.playerSettings.skipChapterEnd;
if (start < Duration.zero && end < Duration.zero) {
return null;
}
// final player = ref.read(absPlayerProvider);
// final bookSettings = ref.watch(bookSettingsProvider(bookId));
// final start = bookSettings.playerSettings.skipChapterStart;
// final end = bookSettings.playerSettings.skipChapterEnd;
// if (start < Duration.zero && end < Duration.zero) {
// return null;
// }
final skipStartEnd = core.SkipStartEnd(
start: start,
end: end,
player: player,
);
ref.onDispose(skipStartEnd.dispose);
return skipStartEnd;
}
}
// final skipStartEnd = core.SkipStartEnd(
// start: start,
// end: end,
// player: player,
// );
// ref.onDispose(skipStartEnd.dispose);
// return skipStartEnd;
// }
// }

View file

@ -1,25 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'skip_start_end_provider.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$skipStartEndHash() => r'45572f40a098f081181e8b8bf9e4913e6e649cdc';
/// See also [SkipStartEnd].
@ProviderFor(SkipStartEnd)
final skipStartEndProvider =
AutoDisposeNotifierProvider<SkipStartEnd, core.SkipStartEnd?>.internal(
SkipStartEnd.new,
name: r'skipStartEndProvider',
debugGetCreateSourceHash:
const bool.fromEnvironment('dart.vm.product') ? null : _$skipStartEndHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef _$SkipStartEnd = AutoDisposeNotifier<core.SkipStartEnd?>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package