mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-17 06:49:34 +00:00
一堆乱七八糟的修改
播放页面增加桌面版
This commit is contained in:
parent
aee1fbde88
commit
3ba35b31b8
116 changed files with 1238 additions and 2592 deletions
58
lib/features/skip_start_end/core/skip_start_end.dart
Normal file
58
lib/features/skip_start_end/core/skip_start_end.dart
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:vaani/features/player/core/audiobook_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 AbsAudioHandler player;
|
||||
|
||||
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) {
|
||||
if (chapter != null &&
|
||||
player.positionInChapter < Duration(seconds: 1)) {
|
||||
Future.microtask(
|
||||
() => throttlerStart
|
||||
.call(() => player.seekInBook(chapter.start + start)),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (end > Duration.zero) {
|
||||
_subscriptions.add(
|
||||
player.positionStreamInChapter.listen((positionChapter) {
|
||||
if (end >
|
||||
(player.currentChapter?.duration ?? Duration.zero) -
|
||||
positionChapter) {
|
||||
Future.microtask(
|
||||
() => throttlerEnd.call(() => player.skipToNext()),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// dispose the timer
|
||||
void dispose() {
|
||||
for (var sub in _subscriptions) {
|
||||
sub.cancel();
|
||||
}
|
||||
throttlerStart.dispose();
|
||||
throttlerEnd.dispose();
|
||||
// _playbackController.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue