mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-16 14:29:35 +00:00
chore: 优化进度条显示
This commit is contained in:
parent
03cec3f4b6
commit
d96995a863
27 changed files with 1229 additions and 1311 deletions
|
|
@ -7,7 +7,7 @@ import 'package:vaani/features/per_book_settings/models/nullable_player_settings
|
|||
|
||||
part 'book_settings_provider.g.dart';
|
||||
|
||||
final _box = AvailableHiveBoxes.individualBookSettingsBox;
|
||||
final _box = HiveBoxes.individualBookSettingsBox;
|
||||
|
||||
final _logger = Logger('BookSettingsProvider');
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:just_audio_background/just_audio_background.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
|
@ -18,8 +19,9 @@ final offset = Duration(milliseconds: 10);
|
|||
final _logger = Logger('AbsAudioPlayer');
|
||||
|
||||
class AbsAudioPlayer {
|
||||
final Ref ref;
|
||||
late final AudioPlayer _player;
|
||||
AbsAudioPlayer(AudioPlayer player) : _player = player {
|
||||
AbsAudioPlayer(AudioPlayer player, this.ref) : _player = player {
|
||||
_player.positionStream.listen((position) {
|
||||
final chapter = currentChapter;
|
||||
if (positionInBook <= (chapter?.start ?? Duration.zero) ||
|
||||
|
|
@ -53,34 +55,23 @@ class AbsAudioPlayer {
|
|||
List<Uri>? downloadedUris,
|
||||
Duration? start,
|
||||
Duration? end,
|
||||
bool force = false,
|
||||
}) async {
|
||||
if (_bookStreamController.nvalue == book) {
|
||||
if (!force && _bookStreamController.nvalue == book) {
|
||||
_logger.info('Book is the same, doing nothing');
|
||||
return;
|
||||
}
|
||||
_bookStreamController.add(book);
|
||||
final appSettings = loadOrCreateAppSettings();
|
||||
|
||||
final currentTrack = book.findTrackAtTime(initialPosition ?? Duration.zero);
|
||||
final indexTrack = book.tracks.indexOf(currentTrack);
|
||||
final positionInTrack = initialPosition != null
|
||||
? initialPosition - currentTrack.startOffset
|
||||
: null;
|
||||
final title = appSettings.notificationSettings.primaryTitle
|
||||
.formatNotificationTitle(book);
|
||||
final artist = appSettings.notificationSettings.secondaryTitle
|
||||
.formatNotificationTitle(book);
|
||||
chapterStreamController
|
||||
.add(book.findChapterAtTime(initialPosition ?? Duration.zero));
|
||||
// final item = MediaItem(
|
||||
// id: book.libraryItemId,
|
||||
// title: title,
|
||||
// artist: artist,
|
||||
// duration: currentChapter?.duration ?? book.duration,
|
||||
// artUri: Uri.parse(
|
||||
// '$baseUrl/api/items/${book.libraryItemId}/cover?token=$token',
|
||||
// ),
|
||||
// );
|
||||
final title = primaryTitle();
|
||||
final artist = secondaryTitle();
|
||||
|
||||
mediaItem(track) => MediaItem(
|
||||
id: book.libraryItemId + track.index.toString(),
|
||||
|
|
@ -91,6 +82,13 @@ class AbsAudioPlayer {
|
|||
'$baseUrl/api/items/${book.libraryItemId}/cover?token=$token',
|
||||
),
|
||||
);
|
||||
if (start != null && start > Duration.zero ||
|
||||
end != null && end > Duration.zero) {
|
||||
_logger.info(
|
||||
'Skip the opening ${start?.inSeconds} seconds, end ${end?.inSeconds} seconds',
|
||||
);
|
||||
}
|
||||
|
||||
List<AudioSource> audioSources = start != null && start > Duration.zero ||
|
||||
end != null && end > Duration.zero
|
||||
? book.tracks
|
||||
|
|
@ -270,6 +268,26 @@ class AbsAudioPlayer {
|
|||
_bookStreamController.close();
|
||||
chapterStreamController.close();
|
||||
}
|
||||
|
||||
String primaryTitle() {
|
||||
final appSettings = ref.read(appSettingsProvider);
|
||||
final currentBook = book;
|
||||
if (currentBook != null) {
|
||||
return appSettings.notificationSettings.primaryTitle
|
||||
.formatNotificationTitle(currentBook, chapter: currentChapter);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
String secondaryTitle() {
|
||||
final appSettings = ref.read(appSettingsProvider);
|
||||
final currentBook = book;
|
||||
if (currentBook != null) {
|
||||
return appSettings.notificationSettings.secondaryTitle
|
||||
.formatNotificationTitle(currentBook, chapter: currentChapter);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Uri _getUri(
|
||||
|
|
@ -328,14 +346,14 @@ extension BookExpandedExtension on BookExpanded {
|
|||
}
|
||||
|
||||
extension FormatNotificationTitle on String {
|
||||
String formatNotificationTitle(BookExpanded book) {
|
||||
String formatNotificationTitle(BookExpanded book, {BookChapter? chapter}) {
|
||||
return replaceAllMapped(
|
||||
RegExp(r'\$(\w+)'),
|
||||
(match) {
|
||||
final type = match.group(1);
|
||||
return NotificationTitleType.values
|
||||
.firstWhere((element) => element.name == type)
|
||||
.extractFrom(book) ??
|
||||
.extractFrom(book, chapter: chapter) ??
|
||||
match.group(0) ??
|
||||
'';
|
||||
},
|
||||
|
|
@ -344,13 +362,16 @@ extension FormatNotificationTitle on String {
|
|||
}
|
||||
|
||||
extension NotificationTitleUtils on NotificationTitleType {
|
||||
String? extractFrom(BookExpanded book) {
|
||||
String? extractFrom(BookExpanded book, {BookChapter? chapter}) {
|
||||
var bookMetadataExpanded = book.metadata.asBookMetadataExpanded;
|
||||
switch (this) {
|
||||
case NotificationTitleType.bookTitle:
|
||||
return bookMetadataExpanded.title;
|
||||
case NotificationTitleType.chapterTitle:
|
||||
// TODO: implement chapter title; depends on https://github.com/Dr-Blank/Vaani/issues/2
|
||||
if (chapter != null) {
|
||||
return chapter.title;
|
||||
}
|
||||
return bookMetadataExpanded.title;
|
||||
case NotificationTitleType.author:
|
||||
return bookMetadataExpanded.authorName;
|
||||
|
|
|
|||
|
|
@ -2,64 +2,24 @@ import 'package:collection/collection.dart';
|
|||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:just_audio/just_audio.dart' as audio;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:shelfsdk/audiobookshelf_api.dart' as api;
|
||||
import 'package:shelfsdk/audiobookshelf_api.dart' as shelfsdk;
|
||||
import 'package:vaani/api/api_provider.dart';
|
||||
import 'package:vaani/api/library_item_provider.dart';
|
||||
import 'package:vaani/db/available_boxes.dart';
|
||||
import 'package:vaani/db/cache/cache_key.dart';
|
||||
import 'package:vaani/features/downloads/providers/download_manager.dart';
|
||||
import 'package:vaani/features/per_book_settings/providers/book_settings_provider.dart';
|
||||
import 'package:vaani/features/player/core/abs_audio_player.dart'
|
||||
show AbsAudioPlayer;
|
||||
import 'package:vaani/features/player/core/abs_audio_player.dart';
|
||||
import 'package:vaani/features/settings/app_settings_provider.dart';
|
||||
import 'package:vaani/shared/extensions/box.dart';
|
||||
import 'package:vaani/shared/extensions/model_conversions.dart';
|
||||
|
||||
part 'abs_provider.g.dart';
|
||||
|
||||
/// 音频播放器 配置
|
||||
// @Riverpod(keepAlive: true)
|
||||
// Future<AudioHandler> configurePlayer(Ref ref) async {
|
||||
// final player = ref.read(absPlayerProvider);
|
||||
// // for playing audio on windows, linux
|
||||
|
||||
// // for configuring how this app will interact with other audio apps
|
||||
// final session = await AudioSession.instance;
|
||||
// await session.configure(const AudioSessionConfiguration.speech());
|
||||
|
||||
// final audioService = await AudioService.init(
|
||||
// builder: () => AbsAudioHandler(player),
|
||||
// config: const AudioServiceConfig(
|
||||
// androidNotificationChannelId: 'dr.blank.vaani.channel.audio',
|
||||
// androidNotificationChannelName: 'ABSPlayback',
|
||||
// androidNotificationChannelDescription:
|
||||
// 'Needed to control audio from lock screen',
|
||||
// androidNotificationOngoing: false,
|
||||
// androidStopForegroundOnPause: false,
|
||||
// androidNotificationIcon: 'drawable/ic_stat_logo',
|
||||
// preloadArtwork: true,
|
||||
// // fastForwardInterval: Duration(seconds: 20),
|
||||
// // rewindInterval: Duration(seconds: 20),
|
||||
// ),
|
||||
// );
|
||||
|
||||
// _logger.finer('created simple player');
|
||||
// return audioService;
|
||||
// }
|
||||
|
||||
// just_audio 播放器
|
||||
// @Riverpod(keepAlive: true)
|
||||
// core.AbsAudioPlayer audioPlayer(Ref ref) {
|
||||
// final player = AbsPlatformAudioPlayer();
|
||||
// // final player = AbsMpvAudioPlayer();
|
||||
// ref.onDispose(player.dispose);
|
||||
// return player;
|
||||
// }
|
||||
|
||||
// 播放器激活状态
|
||||
@riverpod
|
||||
bool playerActive(Ref ref) {
|
||||
return false;
|
||||
return ref.watch(currentBookProvider) != null;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
|
|
@ -76,23 +36,23 @@ class AbsPlayer extends _$AbsPlayer {
|
|||
@override
|
||||
AbsAudioPlayer build() {
|
||||
final audioPlayer = ref.watch(simpleAudioPlayerProvider);
|
||||
return AbsAudioPlayer(audioPlayer);
|
||||
return AbsAudioPlayer(audioPlayer, ref);
|
||||
}
|
||||
|
||||
Future<void> load(
|
||||
api.BookExpanded book, {
|
||||
shelfsdk.BookExpanded book, {
|
||||
Duration? initialPosition,
|
||||
bool play = true,
|
||||
bool force = false,
|
||||
}) async {
|
||||
if (state.book == book || state.book?.libraryItemId == book.libraryItemId) {
|
||||
if (!force &&
|
||||
(state.book == book ||
|
||||
state.book?.libraryItemId == book.libraryItemId)) {
|
||||
state.playOrPause();
|
||||
return;
|
||||
}
|
||||
final api = ref.read(authenticatedApiProvider);
|
||||
|
||||
final downloadManager = ref.read(simpleDownloadManagerProvider);
|
||||
print(downloadManager.basePath);
|
||||
|
||||
final libItem =
|
||||
await ref.read(libraryItemProvider(book.libraryItemId).future);
|
||||
final downloadedUris = await downloadManager.getDownloadedFilesUri(libItem);
|
||||
|
|
@ -112,6 +72,7 @@ class AbsPlayer extends _$AbsPlayer {
|
|||
downloadedUris: downloadedUris,
|
||||
start: bookSettings.playerSettings.skipChapterStart,
|
||||
end: bookSettings.playerSettings.skipChapterEnd,
|
||||
force: force,
|
||||
);
|
||||
// set the volume
|
||||
await state.setVolume(
|
||||
|
|
@ -131,67 +92,6 @@ class AbsPlayer extends _$AbsPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
/// 音频播放器 riverpod状态
|
||||
// @Riverpod(keepAlive: true)
|
||||
// class AbsPlayer extends _$AbsPlayer {
|
||||
// @override
|
||||
// core.AbsAudioPlayer build() {
|
||||
// final audioPlayer = ref.watch(audioPlayerProvider);
|
||||
// return audioPlayer;
|
||||
// }
|
||||
|
||||
// Future<void> load(
|
||||
// api.BookExpanded book, {
|
||||
// Duration? initialPosition,
|
||||
// bool play = true,
|
||||
// }) async {
|
||||
// if (state.book == book || state.book?.libraryItemId == book.libraryItemId) {
|
||||
// state.playOrPause();
|
||||
// return;
|
||||
// }
|
||||
// final api = ref.read(authenticatedApiProvider);
|
||||
|
||||
// final downloadManager = ref.read(simpleDownloadManagerProvider);
|
||||
// print(downloadManager.basePath);
|
||||
|
||||
// final libItem =
|
||||
// await ref.read(libraryItemProvider(book.libraryItemId).future);
|
||||
// final downloadedUris = await downloadManager.getDownloadedFilesUri(libItem);
|
||||
|
||||
// final bookSettings = ref.read(bookSettingsProvider(book.libraryItemId));
|
||||
// var bookPlayerSettings = bookSettings.playerSettings;
|
||||
// var appPlayerSettings = ref.read(appSettingsProvider).playerSettings;
|
||||
|
||||
// var configurePlayerForEveryBook =
|
||||
// appPlayerSettings.configurePlayerForEveryBook;
|
||||
|
||||
// await state.load(
|
||||
// book,
|
||||
// baseUrl: api.baseUrl,
|
||||
// token: api.token!,
|
||||
// initialPosition: initialPosition,
|
||||
// downloadedUris: downloadedUris,
|
||||
// start: bookSettings.playerSettings.skipChapterStart,
|
||||
// end: bookSettings.playerSettings.skipChapterEnd,
|
||||
// );
|
||||
// // set the volume
|
||||
// await state.setVolume(
|
||||
// configurePlayerForEveryBook
|
||||
// ? bookPlayerSettings.preferredDefaultVolume ??
|
||||
// appPlayerSettings.preferredDefaultVolume
|
||||
// : appPlayerSettings.preferredDefaultVolume,
|
||||
// );
|
||||
// // set the speed
|
||||
// await state.setSpeed(
|
||||
// configurePlayerForEveryBook
|
||||
// ? bookPlayerSettings.preferredDefaultSpeed ??
|
||||
// appPlayerSettings.preferredDefaultSpeed
|
||||
// : appPlayerSettings.preferredDefaultSpeed,
|
||||
// );
|
||||
// if (play) await state.play();
|
||||
// }
|
||||
// }
|
||||
|
||||
@riverpod
|
||||
class PlayerState extends _$PlayerState {
|
||||
@override
|
||||
|
|
@ -218,21 +118,24 @@ class PlayerState extends _$PlayerState {
|
|||
}
|
||||
|
||||
@riverpod
|
||||
Future<Duration?> currentTime(Ref ref, String libraryItemId) async {
|
||||
final me = await ref.watch(meProvider.future);
|
||||
final userProgress = me.mediaProgress
|
||||
?.firstWhereOrNull((element) => element.libraryItemId == libraryItemId);
|
||||
return userProgress?.currentTime;
|
||||
class CurrentTime extends _$CurrentTime {
|
||||
@override
|
||||
Future<shelfsdk.MediaProgress?> build(String libraryItemId) async {
|
||||
final me = await ref.watch(meProvider.future);
|
||||
final userProgress = me.mediaProgress
|
||||
?.firstWhereOrNull((element) => element.libraryItemId == libraryItemId);
|
||||
return userProgress;
|
||||
}
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class CurrentBook extends _$CurrentBook {
|
||||
@override
|
||||
api.BookExpanded? build() {
|
||||
shelfsdk.BookExpanded? build() {
|
||||
listenSelf((previous, next) {
|
||||
if (previous == null && next == null) {
|
||||
final activeLibraryItemId = AvailableHiveBoxes.basicBox
|
||||
.getAs<String>(CacheKey.activeLibraryItemId);
|
||||
final activeLibraryItemId =
|
||||
HiveBoxes.basicBox.getAs<String>(CacheKey.activeLibraryItemId);
|
||||
if (activeLibraryItemId != null) {
|
||||
update(activeLibraryItemId, play: false);
|
||||
}
|
||||
|
|
@ -240,31 +143,29 @@ class CurrentBook extends _$CurrentBook {
|
|||
});
|
||||
return null;
|
||||
}
|
||||
// @override
|
||||
// api.BookExpanded? build() {
|
||||
// final player = ref.read(absPlayerProvider);
|
||||
// player.bookStream.listen((book) {
|
||||
// if (book != state) {
|
||||
// state = book;
|
||||
// }
|
||||
// });
|
||||
// return player.book;
|
||||
// }
|
||||
|
||||
Future<void> update(String libraryItemId, {bool play = true}) async {
|
||||
if (state?.libraryItemId == libraryItemId) {
|
||||
Future<void> update(
|
||||
String libraryItemId, {
|
||||
bool play = true,
|
||||
bool force = false,
|
||||
Duration? currentTime,
|
||||
}) async {
|
||||
if (!force && (state?.libraryItemId == libraryItemId)) {
|
||||
ref.read(absPlayerProvider).playOrPause();
|
||||
return;
|
||||
}
|
||||
final book = await ref.read(libraryItemProvider(libraryItemId).future);
|
||||
state = book.media.asBookExpanded;
|
||||
final currentTime =
|
||||
final mediaProgress =
|
||||
await ref.read(currentTimeProvider(libraryItemId).future);
|
||||
await ref
|
||||
.read(absPlayerProvider.notifier)
|
||||
.load(state!, initialPosition: currentTime, play: play);
|
||||
await ref.read(absPlayerProvider.notifier).load(
|
||||
state!,
|
||||
initialPosition: currentTime ?? mediaProgress?.currentTime,
|
||||
play: play,
|
||||
force: force,
|
||||
);
|
||||
if (play) {
|
||||
AvailableHiveBoxes.basicBox.put(
|
||||
HiveBoxes.basicBox.put(
|
||||
CacheKey.activeLibraryItemId,
|
||||
libraryItemId,
|
||||
);
|
||||
|
|
@ -275,7 +176,7 @@ class CurrentBook extends _$CurrentBook {
|
|||
@riverpod
|
||||
class CurrentChapter extends _$CurrentChapter {
|
||||
@override
|
||||
api.BookChapter? build() {
|
||||
shelfsdk.BookChapter? build() {
|
||||
final player = ref.read(absPlayerProvider);
|
||||
player.chapterStream.listen((chapter) {
|
||||
if (chapter != state) {
|
||||
|
|
@ -286,7 +187,48 @@ class CurrentChapter extends _$CurrentChapter {
|
|||
}
|
||||
}
|
||||
|
||||
/// 进度条显示
|
||||
// 进度条总时长
|
||||
@riverpod
|
||||
Stream<Duration> positionChapter(Ref ref) {
|
||||
return ref.read(absPlayerProvider).positionInChapterStream;
|
||||
Duration total(Ref ref) {
|
||||
final currentBook = ref.watch(currentBookProvider);
|
||||
final currentChapter = ref.watch(currentChapterProvider);
|
||||
final playerSettings =
|
||||
ref.watch(appSettingsProvider.select((v) => v.playerSettings));
|
||||
final showChapterProgress =
|
||||
playerSettings.expandedPlayerSettings.showChapterProgress;
|
||||
return showChapterProgress
|
||||
? ((currentChapter?.end ?? Duration.zero) -
|
||||
(currentChapter?.start ?? Duration.zero))
|
||||
: currentBook?.duration ?? Duration.zero;
|
||||
}
|
||||
|
||||
// 进度条当前时长
|
||||
@riverpod
|
||||
Stream<Duration> progress(Ref ref) {
|
||||
final player = ref.read(absPlayerProvider);
|
||||
final playerSettings =
|
||||
ref.watch(appSettingsProvider.select((v) => v.playerSettings));
|
||||
final showChapterProgress =
|
||||
playerSettings.expandedPlayerSettings.showChapterProgress;
|
||||
return player.positionStream.map((position) {
|
||||
return showChapterProgress
|
||||
? player.getPositionInChapter(position)
|
||||
: player.getPositionInBook(position);
|
||||
});
|
||||
}
|
||||
|
||||
// 进度条已加载时长
|
||||
@riverpod
|
||||
Stream<Duration> progressBuffered(Ref ref) {
|
||||
final player = ref.read(absPlayerProvider);
|
||||
final playerSettings =
|
||||
ref.watch(appSettingsProvider.select((v) => v.playerSettings));
|
||||
final showChapterProgress =
|
||||
playerSettings.expandedPlayerSettings.showChapterProgress;
|
||||
return player.bufferedPositionStream.map((position) {
|
||||
return showChapterProgress
|
||||
? player.getPositionInChapter(position)
|
||||
: player.getPositionInBook(position);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@ part of 'abs_provider.dart';
|
|||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$playerActiveHash() => r'86831758035aa69d74f42ebde0a19bf7ef830910';
|
||||
String _$playerActiveHash() => r'4d3e7181cf66bfdb46d5caaece56cde07f610cc4';
|
||||
|
||||
/// 音频播放器 配置
|
||||
///
|
||||
/// Copied from [playerActive].
|
||||
/// See also [playerActive].
|
||||
@ProviderFor(playerActive)
|
||||
final playerActiveProvider = AutoDisposeProvider<bool>.internal(
|
||||
playerActive,
|
||||
|
|
@ -41,7 +39,87 @@ final simpleAudioPlayerProvider = Provider<audio.AudioPlayer>.internal(
|
|||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef SimpleAudioPlayerRef = ProviderRef<audio.AudioPlayer>;
|
||||
String _$currentTimeHash() => r'3e7f99dbf48242a5fa0a4239a0f696535d0b4ac9';
|
||||
String _$totalHash() => r'2d01953862a875f6e66fe3af56868e819e33fcc8';
|
||||
|
||||
/// 进度条显示
|
||||
///
|
||||
/// Copied from [total].
|
||||
@ProviderFor(total)
|
||||
final totalProvider = AutoDisposeProvider<Duration>.internal(
|
||||
total,
|
||||
name: r'totalProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$totalHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef TotalRef = AutoDisposeProviderRef<Duration>;
|
||||
String _$progressHash() => r'7ed041be2d26a437becc9ab624322b47efbee06e';
|
||||
|
||||
/// See also [progress].
|
||||
@ProviderFor(progress)
|
||||
final progressProvider = AutoDisposeStreamProvider<Duration>.internal(
|
||||
progress,
|
||||
name: r'progressProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$progressHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef ProgressRef = AutoDisposeStreamProviderRef<Duration>;
|
||||
String _$progressBufferedHash() => r'20f886a5ad8bd4eb031eceb845201dc61dfd5fca';
|
||||
|
||||
/// See also [progressBuffered].
|
||||
@ProviderFor(progressBuffered)
|
||||
final progressBufferedProvider = AutoDisposeStreamProvider<Duration>.internal(
|
||||
progressBuffered,
|
||||
name: r'progressBufferedProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$progressBufferedHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef ProgressBufferedRef = AutoDisposeStreamProviderRef<Duration>;
|
||||
String _$absPlayerHash() => r'c43c02b600326c2d47b900cb3977cd9fae201463';
|
||||
|
||||
/// See also [AbsPlayer].
|
||||
@ProviderFor(AbsPlayer)
|
||||
final absPlayerProvider = NotifierProvider<AbsPlayer, AbsAudioPlayer>.internal(
|
||||
AbsPlayer.new,
|
||||
name: r'absPlayerProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$absPlayerHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$AbsPlayer = Notifier<AbsAudioPlayer>;
|
||||
String _$playerStateHash() => r'eb79bd816714f721da1c4226d4447de5dc55fc5c';
|
||||
|
||||
/// See also [PlayerState].
|
||||
@ProviderFor(PlayerState)
|
||||
final playerStateProvider =
|
||||
AutoDisposeNotifierProvider<PlayerState, audio.PlayerState>.internal(
|
||||
PlayerState.new,
|
||||
name: r'playerStateProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$playerStateHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$PlayerState = AutoDisposeNotifier<audio.PlayerState>;
|
||||
String _$currentTimeHash() => r'e2cf66f5f04cd51f5ddafd64ace395ec3bf0ede2';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
|
|
@ -64,16 +142,25 @@ class _SystemHash {
|
|||
}
|
||||
}
|
||||
|
||||
/// See also [currentTime].
|
||||
@ProviderFor(currentTime)
|
||||
abstract class _$CurrentTime
|
||||
extends BuildlessAutoDisposeAsyncNotifier<shelfsdk.MediaProgress?> {
|
||||
late final String libraryItemId;
|
||||
|
||||
FutureOr<shelfsdk.MediaProgress?> build(
|
||||
String libraryItemId,
|
||||
);
|
||||
}
|
||||
|
||||
/// See also [CurrentTime].
|
||||
@ProviderFor(CurrentTime)
|
||||
const currentTimeProvider = CurrentTimeFamily();
|
||||
|
||||
/// See also [currentTime].
|
||||
class CurrentTimeFamily extends Family<AsyncValue<Duration?>> {
|
||||
/// See also [currentTime].
|
||||
/// See also [CurrentTime].
|
||||
class CurrentTimeFamily extends Family<AsyncValue<shelfsdk.MediaProgress?>> {
|
||||
/// See also [CurrentTime].
|
||||
const CurrentTimeFamily();
|
||||
|
||||
/// See also [currentTime].
|
||||
/// See also [CurrentTime].
|
||||
CurrentTimeProvider call(
|
||||
String libraryItemId,
|
||||
) {
|
||||
|
|
@ -106,16 +193,14 @@ class CurrentTimeFamily extends Family<AsyncValue<Duration?>> {
|
|||
String? get name => r'currentTimeProvider';
|
||||
}
|
||||
|
||||
/// See also [currentTime].
|
||||
class CurrentTimeProvider extends AutoDisposeFutureProvider<Duration?> {
|
||||
/// See also [currentTime].
|
||||
/// See also [CurrentTime].
|
||||
class CurrentTimeProvider extends AutoDisposeAsyncNotifierProviderImpl<
|
||||
CurrentTime, shelfsdk.MediaProgress?> {
|
||||
/// See also [CurrentTime].
|
||||
CurrentTimeProvider(
|
||||
String libraryItemId,
|
||||
) : this._internal(
|
||||
(ref) => currentTime(
|
||||
ref as CurrentTimeRef,
|
||||
libraryItemId,
|
||||
),
|
||||
() => CurrentTime()..libraryItemId = libraryItemId,
|
||||
from: currentTimeProvider,
|
||||
name: r'currentTimeProvider',
|
||||
debugGetCreateSourceHash:
|
||||
|
|
@ -141,13 +226,20 @@ class CurrentTimeProvider extends AutoDisposeFutureProvider<Duration?> {
|
|||
final String libraryItemId;
|
||||
|
||||
@override
|
||||
Override overrideWith(
|
||||
FutureOr<Duration?> Function(CurrentTimeRef provider) create,
|
||||
FutureOr<shelfsdk.MediaProgress?> runNotifierBuild(
|
||||
covariant CurrentTime notifier,
|
||||
) {
|
||||
return notifier.build(
|
||||
libraryItemId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Override overrideWith(CurrentTime Function() create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: CurrentTimeProvider._internal(
|
||||
(ref) => create(ref as CurrentTimeRef),
|
||||
() => create()..libraryItemId = libraryItemId,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
|
|
@ -159,7 +251,8 @@ class CurrentTimeProvider extends AutoDisposeFutureProvider<Duration?> {
|
|||
}
|
||||
|
||||
@override
|
||||
AutoDisposeFutureProviderElement<Duration?> createElement() {
|
||||
AutoDisposeAsyncNotifierProviderElement<CurrentTime, shelfsdk.MediaProgress?>
|
||||
createElement() {
|
||||
return _CurrentTimeProviderElement(this);
|
||||
}
|
||||
|
||||
|
|
@ -179,73 +272,27 @@ class CurrentTimeProvider extends AutoDisposeFutureProvider<Duration?> {
|
|||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
mixin CurrentTimeRef on AutoDisposeFutureProviderRef<Duration?> {
|
||||
mixin CurrentTimeRef
|
||||
on AutoDisposeAsyncNotifierProviderRef<shelfsdk.MediaProgress?> {
|
||||
/// The parameter `libraryItemId` of this provider.
|
||||
String get libraryItemId;
|
||||
}
|
||||
|
||||
class _CurrentTimeProviderElement
|
||||
extends AutoDisposeFutureProviderElement<Duration?> with CurrentTimeRef {
|
||||
extends AutoDisposeAsyncNotifierProviderElement<CurrentTime,
|
||||
shelfsdk.MediaProgress?> with CurrentTimeRef {
|
||||
_CurrentTimeProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get libraryItemId => (origin as CurrentTimeProvider).libraryItemId;
|
||||
}
|
||||
|
||||
String _$positionChapterHash() => r'ac6148e92363fad849713c07045503653dcaa7e8';
|
||||
|
||||
/// See also [positionChapter].
|
||||
@ProviderFor(positionChapter)
|
||||
final positionChapterProvider = AutoDisposeStreamProvider<Duration>.internal(
|
||||
positionChapter,
|
||||
name: r'positionChapterProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$positionChapterHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef PositionChapterRef = AutoDisposeStreamProviderRef<Duration>;
|
||||
String _$absPlayerHash() => r'370f576d3d3a2196d1a93f2046005c1a3298d994';
|
||||
|
||||
/// See also [AbsPlayer].
|
||||
@ProviderFor(AbsPlayer)
|
||||
final absPlayerProvider = NotifierProvider<AbsPlayer, AbsAudioPlayer>.internal(
|
||||
AbsPlayer.new,
|
||||
name: r'absPlayerProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$absPlayerHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$AbsPlayer = Notifier<AbsAudioPlayer>;
|
||||
String _$playerStateHash() => r'eb79bd816714f721da1c4226d4447de5dc55fc5c';
|
||||
|
||||
/// 音频播放器 riverpod状态
|
||||
///
|
||||
/// Copied from [PlayerState].
|
||||
@ProviderFor(PlayerState)
|
||||
final playerStateProvider =
|
||||
AutoDisposeNotifierProvider<PlayerState, audio.PlayerState>.internal(
|
||||
PlayerState.new,
|
||||
name: r'playerStateProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$playerStateHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$PlayerState = AutoDisposeNotifier<audio.PlayerState>;
|
||||
String _$currentBookHash() => r'85de9041d356e214761b65bd1b7b74321d5a9221';
|
||||
String _$currentBookHash() => r'f13ba110d104be8bae48972d6fd266d461d30898';
|
||||
|
||||
/// See also [CurrentBook].
|
||||
@ProviderFor(CurrentBook)
|
||||
final currentBookProvider =
|
||||
AutoDisposeNotifierProvider<CurrentBook, api.BookExpanded?>.internal(
|
||||
AutoDisposeNotifierProvider<CurrentBook, shelfsdk.BookExpanded?>.internal(
|
||||
CurrentBook.new,
|
||||
name: r'currentBookProvider',
|
||||
debugGetCreateSourceHash:
|
||||
|
|
@ -254,13 +301,13 @@ final currentBookProvider =
|
|||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$CurrentBook = AutoDisposeNotifier<api.BookExpanded?>;
|
||||
String _$currentChapterHash() => r'aff83aed7d098099805ec7d72ea84fff3a298522';
|
||||
typedef _$CurrentBook = AutoDisposeNotifier<shelfsdk.BookExpanded?>;
|
||||
String _$currentChapterHash() => r'e8d867067f383372afd758186f13950a6746ba85';
|
||||
|
||||
/// See also [CurrentChapter].
|
||||
@ProviderFor(CurrentChapter)
|
||||
final currentChapterProvider =
|
||||
AutoDisposeNotifierProvider<CurrentChapter, api.BookChapter?>.internal(
|
||||
AutoDisposeNotifierProvider<CurrentChapter, shelfsdk.BookChapter?>.internal(
|
||||
CurrentChapter.new,
|
||||
name: r'currentChapterProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
|
|
@ -270,6 +317,6 @@ final currentChapterProvider =
|
|||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$CurrentChapter = AutoDisposeNotifier<api.BookChapter?>;
|
||||
typedef _$CurrentChapter = AutoDisposeNotifier<shelfsdk.BookChapter?>;
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -105,22 +105,11 @@ class PlayerExpanded extends HookConsumerWidget {
|
|||
left: AppElementSizes.paddingRegular,
|
||||
right: AppElementSizes.paddingRegular,
|
||||
),
|
||||
child: const AudiobookChapterProgressBar(),
|
||||
child: const AbsDesktopProgressBar(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
width: imageSize,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: AppElementSizes.paddingRegular,
|
||||
right: AppElementSizes.paddingRegular,
|
||||
),
|
||||
child: const AudiobookProgressBar(),
|
||||
),
|
||||
),
|
||||
|
||||
// the chapter skip buttons, seek 30 seconds back and forward, and play/pause button
|
||||
Expanded(
|
||||
flex: 2,
|
||||
|
|
|
|||
|
|
@ -110,9 +110,9 @@ class PlayerExpandedDesktop extends HookConsumerWidget {
|
|||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: AppElementSizes.paddingRegular,
|
||||
horizontal: AppElementSizes.paddingLarge,
|
||||
),
|
||||
child: const AudiobookChapterProgressBar(
|
||||
child: const AbsDesktopProgressBar(
|
||||
timeLabelLocation: TimeLabelLocation.sides,
|
||||
),
|
||||
),
|
||||
|
|
@ -140,10 +140,10 @@ class PlayerExpandedDesktop extends HookConsumerWidget {
|
|||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Row(),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Hero(
|
||||
tag: HeroTagPrefixes.controlsCenter,
|
||||
child: const PlayerControlsDesktopCenter(),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:vaani/constants/hero_tag_conventions.dart';
|
||||
|
|
@ -8,12 +7,12 @@ import 'package:vaani/features/player/providers/abs_provider.dart';
|
|||
import 'package:vaani/features/player/view/widgets/audiobook_player_seek_button.dart';
|
||||
import 'package:vaani/features/player/view/widgets/audiobook_player_seek_chapter_button.dart';
|
||||
import 'package:vaani/features/player/view/widgets/player_player_pause_button.dart';
|
||||
import 'package:vaani/features/player/view/widgets/player_progress_bar.dart';
|
||||
import 'package:vaani/features/player/view/widgets/player_speed_adjust_button.dart';
|
||||
import 'package:vaani/features/skip_start_end/view/skip_start_end_button.dart';
|
||||
import 'package:vaani/features/sleep_timer/view/sleep_timer_button.dart';
|
||||
import 'package:vaani/globals.dart';
|
||||
import 'package:vaani/router/router.dart';
|
||||
import 'package:vaani/shared/extensions/chapter.dart';
|
||||
import 'package:vaani/shared/extensions/model_conversions.dart';
|
||||
import 'package:vaani/shared/widgets/shelves/book_shelf.dart';
|
||||
|
||||
|
|
@ -29,16 +28,16 @@ class PlayerMinimized extends HookConsumerWidget {
|
|||
final size = MediaQuery.of(context).size;
|
||||
// 竖屏
|
||||
final isVertical = size.height > size.width;
|
||||
return Container(
|
||||
return SizedBox(
|
||||
height: playerMinHeight,
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
// color: Theme.of(context).colorScheme.surface,
|
||||
child: Stack(
|
||||
alignment: Alignment.topCenter,
|
||||
children: [
|
||||
isVertical
|
||||
? const PlayerMinimizedControls()
|
||||
: const PlayerMinimizedControlsDesktop(),
|
||||
const PlayerMinimizedProgress(),
|
||||
const AbsMinimizedProgress(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
@ -145,36 +144,14 @@ class PlayerMinimizedControls extends HookConsumerWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class PlayerMinimizedProgress extends HookConsumerWidget {
|
||||
const PlayerMinimizedProgress({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final currentChapter = ref.watch(currentChapterProvider);
|
||||
|
||||
final progress = useStream(
|
||||
ref.read(absPlayerProvider).positionInChapterStream,
|
||||
initialData: Duration.zero,
|
||||
);
|
||||
return SizedBox(
|
||||
height: AppElementSizes.barHeight,
|
||||
child: LinearProgressIndicator(
|
||||
value: (progress.data ?? Duration.zero).inSeconds /
|
||||
(currentChapter?.duration.inSeconds ?? 1),
|
||||
// color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
// backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PlayerMinimizedControlsDesktop extends HookConsumerWidget {
|
||||
const PlayerMinimizedControlsDesktop({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final currentBook = ref.watch(currentBookProvider);
|
||||
final currentChapter = ref.watch(currentChapterProvider);
|
||||
final absPlayer = ref.watch(absPlayerProvider);
|
||||
ref.watch(currentChapterProvider);
|
||||
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click, // 桌面端显示手型光标
|
||||
|
|
@ -210,7 +187,8 @@ class PlayerMinimizedControlsDesktop extends HookConsumerWidget {
|
|||
},
|
||||
child: Hero(
|
||||
tag: HeroTagPrefixes.bookCoverWith(
|
||||
currentBook?.libraryItemId),
|
||||
currentBook?.libraryItemId,
|
||||
),
|
||||
child: BookCoverWidget(
|
||||
playerMinHeight,
|
||||
itemId: currentBook?.libraryItemId,
|
||||
|
|
@ -231,18 +209,14 @@ class PlayerMinimizedControlsDesktop extends HookConsumerWidget {
|
|||
children: [
|
||||
// AutoScrollText(
|
||||
Text(
|
||||
currentChapter?.title ??
|
||||
currentBook?.metadata.title ??
|
||||
'',
|
||||
absPlayer.primaryTitle(),
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis,
|
||||
// velocity:
|
||||
// const Velocity(pixelsPerSecond: Offset(16, 0)),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
Text(
|
||||
currentBook?.metadata.asBookMetadataExpanded
|
||||
.authorName ??
|
||||
'',
|
||||
absPlayer.secondaryTitle(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context)
|
||||
|
|
@ -263,6 +237,7 @@ class PlayerMinimizedControlsDesktop extends HookConsumerWidget {
|
|||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Hero(
|
||||
tag: HeroTagPrefixes.controlsCenter,
|
||||
child: const PlayerControlsDesktopCenter(),
|
||||
|
|
|
|||
|
|
@ -1,60 +1,44 @@
|
|||
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:vaani/constants/sizes.dart';
|
||||
import 'package:vaani/features/player/providers/abs_provider.dart';
|
||||
import 'package:vaani/features/settings/app_settings_provider.dart';
|
||||
|
||||
// 章节进度
|
||||
class AudiobookChapterProgressBar extends HookConsumerWidget {
|
||||
/// 进度条展示 根据设置显示章节进度或整本书的进度
|
||||
class AbsDesktopProgressBar extends HookConsumerWidget {
|
||||
final TimeLabelLocation timeLabelLocation;
|
||||
const AudiobookChapterProgressBar({
|
||||
const AbsDesktopProgressBar({
|
||||
super.key,
|
||||
this.timeLabelLocation = TimeLabelLocation.below,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final book = ref.watch(currentBookProvider);
|
||||
final player = ref.watch(absPlayerProvider);
|
||||
final currentChapter = ref.watch(currentChapterProvider);
|
||||
final position = useStream(
|
||||
player.positionInBookStream,
|
||||
initialData: const Duration(seconds: 0),
|
||||
);
|
||||
final buffered = useStream(
|
||||
player.bufferedPositionInBookStream,
|
||||
initialData: const Duration(seconds: 0),
|
||||
);
|
||||
final playerSettings =
|
||||
ref.watch(appSettingsProvider.select((v) => v.playerSettings));
|
||||
final showChapterProgress =
|
||||
playerSettings.expandedPlayerSettings.showChapterProgress;
|
||||
|
||||
// now find the chapter that corresponds to the current time
|
||||
// and calculate the progress of the current chapter
|
||||
final currentChapterProgress = currentChapter == null
|
||||
? null
|
||||
: (player.positionInBook - currentChapter.start);
|
||||
final position = ref.watch(progressProvider);
|
||||
final buffered = ref.watch(progressBufferedProvider);
|
||||
|
||||
final currentChapterBuffered = currentChapter == null
|
||||
? null
|
||||
: (player.bufferedPositionInBook - currentChapter.start);
|
||||
|
||||
final progress =
|
||||
currentChapterProgress ?? position.data ?? const Duration(seconds: 0);
|
||||
final total = currentChapter == null
|
||||
? book?.duration ?? const Duration(seconds: 0)
|
||||
: currentChapter.end - currentChapter.start;
|
||||
final total = ref.watch(totalProvider);
|
||||
return ProgressBar(
|
||||
progress: progress,
|
||||
progress: position.requireValue,
|
||||
total: total,
|
||||
// ! TODO add onSeek
|
||||
onSeek: (duration) {
|
||||
player.seekInBook(
|
||||
duration + (currentChapter?.start ?? const Duration(seconds: 0)),
|
||||
duration +
|
||||
(showChapterProgress
|
||||
? (currentChapter?.start ?? Duration.zero)
|
||||
: Duration.zero),
|
||||
);
|
||||
// player.seek(duration);
|
||||
},
|
||||
thumbRadius: 8,
|
||||
buffered:
|
||||
currentChapterBuffered ?? buffered.data ?? const Duration(seconds: 0),
|
||||
buffered: buffered.requireValue,
|
||||
bufferedBarColor: Theme.of(context).colorScheme.secondary,
|
||||
timeLabelType: TimeLabelType.remainingTime,
|
||||
timeLabelLocation: timeLabelLocation,
|
||||
|
|
@ -63,26 +47,19 @@ class AudiobookChapterProgressBar extends HookConsumerWidget {
|
|||
}
|
||||
|
||||
// 书籍进度 简化版
|
||||
class AudiobookProgressBar extends HookConsumerWidget {
|
||||
const AudiobookProgressBar({
|
||||
super.key,
|
||||
});
|
||||
class AbsMinimizedProgress extends HookConsumerWidget {
|
||||
const AbsMinimizedProgress({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final book = ref.watch(currentBookProvider);
|
||||
final player = ref.read(absPlayerProvider);
|
||||
final position = useStream(
|
||||
player.positionInBookStream,
|
||||
initialData: const Duration(seconds: 0),
|
||||
);
|
||||
|
||||
final position = ref.watch(progressProvider);
|
||||
final total = ref.watch(totalProvider);
|
||||
return SizedBox(
|
||||
height: AppElementSizes.barHeightLarge,
|
||||
height: AppElementSizes.barHeight,
|
||||
child: LinearProgressIndicator(
|
||||
value: (position.data ?? const Duration(seconds: 0)).inSeconds /
|
||||
(book?.duration ?? const Duration(seconds: 0)).inSeconds,
|
||||
borderRadius: BorderRadiusGeometry.all(Radius.circular(10)),
|
||||
value: total > Duration.zero
|
||||
? ((position.value ?? Duration.zero).inSeconds / total.inSeconds)
|
||||
: 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import 'package:vaani/shared/extensions/obfuscation.dart';
|
|||
|
||||
part 'api_settings_provider.g.dart';
|
||||
|
||||
final _box = AvailableHiveBoxes.apiSettingsBox;
|
||||
final _box = HiveBoxes.apiSettingsBox;
|
||||
|
||||
final _logger = Logger('ApiSettingsProvider');
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import 'package:vaani/features/settings/models/app_settings.dart' as model;
|
|||
|
||||
part 'app_settings_provider.g.dart';
|
||||
|
||||
final _box = AvailableHiveBoxes.userPrefsBox;
|
||||
final _box = HiveBoxes.userPrefsBox;
|
||||
|
||||
final _logger = Logger('AppSettingsProvider');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// ignore_for_file: unreachable_switch_default
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
// ignore_for_file: unreachable_switch_default, unused_element
|
||||
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:vaani/features/player/providers/abs_provider.dart'
|
||||
hide AudioPlayer;
|
||||
import 'package:vaani/features/player/providers/abs_provider.dart';
|
||||
import 'package:vaani/features/settings/app_settings_provider.dart'
|
||||
show appSettingsProvider;
|
||||
import 'package:vaani/features/settings/models/app_settings.dart';
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ class PlayerSkipChapterStartEnd extends HookConsumerWidget {
|
|||
bookSettings.copyWith
|
||||
.playerSettings(skipChapterStart: interval),
|
||||
);
|
||||
reloadPlayer(ref);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
@ -97,6 +98,7 @@ class PlayerSkipChapterStartEnd extends HookConsumerWidget {
|
|||
bookSettings.copyWith
|
||||
.playerSettings(skipChapterEnd: interval),
|
||||
);
|
||||
reloadPlayer(ref);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
@ -104,4 +106,15 @@ class PlayerSkipChapterStartEnd extends HookConsumerWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
void reloadPlayer(WidgetRef ref) {
|
||||
final currentBook = ref.watch(currentBookProvider);
|
||||
if (currentBook == null) {
|
||||
return;
|
||||
}
|
||||
final absPlayer = ref.read(absPlayerProvider);
|
||||
final positionInBook = absPlayer.positionInBook;
|
||||
ref.read(currentBookProvider.notifier).update(currentBook.libraryItemId,
|
||||
force: true, currentTime: positionInBook);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
lib/features/statistics/abs_statistics.dart
Normal file
16
lib/features/statistics/abs_statistics.dart
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class LibraryStatisticsPage extends HookConsumerWidget {
|
||||
const LibraryStatisticsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('统计'),
|
||||
),
|
||||
// body: Text('统计'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue