mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-24 03:49:30 +00:00
player seek and chapter change
This commit is contained in:
parent
01b3dead49
commit
d01855c218
17 changed files with 1721 additions and 305 deletions
|
|
@ -9,3 +9,30 @@ BookExpanded? currentlyPlayingBook(CurrentlyPlayingBookRef ref) {
|
|||
final player = ref.watch(audiobookPlayerProvider);
|
||||
return player.book;
|
||||
}
|
||||
|
||||
/// provided the current chapter of the book being played
|
||||
@riverpod
|
||||
BookChapter? currentPlayingChapter(CurrentPlayingChapterRef ref) {
|
||||
final player = ref.watch(audiobookPlayerProvider);
|
||||
// get the current timestamp
|
||||
final currentTimestamp = player.position;
|
||||
// get the chapter that contains the current timestamp
|
||||
return player.book?.chapters.firstWhere(
|
||||
(element) =>
|
||||
element.start <= currentTimestamp && element.end >= currentTimestamp,
|
||||
);
|
||||
}
|
||||
|
||||
/// provides the book metadata of the currently playing book
|
||||
@riverpod
|
||||
BookMetadataExpanded? currentBookMetadata(CurrentBookMetadataRef ref) {
|
||||
final player = ref.watch(audiobookPlayerProvider);
|
||||
if (player.book == null) return null;
|
||||
return BookMetadataExpanded.fromJson(player.book!.metadata.toJson());
|
||||
}
|
||||
|
||||
// /// volume of the player [0, 1]
|
||||
// @riverpod
|
||||
// double currentVolume(CurrentVolumeRef ref) {
|
||||
// return 1;
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -23,5 +23,43 @@ final currentlyPlayingBookProvider =
|
|||
);
|
||||
|
||||
typedef CurrentlyPlayingBookRef = AutoDisposeProviderRef<BookExpanded?>;
|
||||
String _$currentPlayingChapterHash() =>
|
||||
r'562416b7e0068aaba9138cb8e0ed7a5ddba8e6c6';
|
||||
|
||||
/// provided the current chapter of the book being played
|
||||
///
|
||||
/// Copied from [currentPlayingChapter].
|
||||
@ProviderFor(currentPlayingChapter)
|
||||
final currentPlayingChapterProvider =
|
||||
AutoDisposeProvider<BookChapter?>.internal(
|
||||
currentPlayingChapter,
|
||||
name: r'currentPlayingChapterProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$currentPlayingChapterHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef CurrentPlayingChapterRef = AutoDisposeProviderRef<BookChapter?>;
|
||||
String _$currentBookMetadataHash() =>
|
||||
r'02b462a051fce5bcbdad6fdb708b60256fbb588c';
|
||||
|
||||
/// provides the book metadata of the currently playing book
|
||||
///
|
||||
/// Copied from [currentBookMetadata].
|
||||
@ProviderFor(currentBookMetadata)
|
||||
final currentBookMetadataProvider =
|
||||
AutoDisposeProvider<BookMetadataExpanded?>.internal(
|
||||
currentBookMetadata,
|
||||
name: r'currentBookMetadataProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$currentBookMetadataHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef CurrentBookMetadataRef = AutoDisposeProviderRef<BookMetadataExpanded?>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|||
part 'player_form.g.dart';
|
||||
|
||||
const double playerMinHeight = 70;
|
||||
const miniplayerPercentageDeclaration = 0.2;
|
||||
// const miniplayerPercentageDeclaration = 0.2;
|
||||
|
||||
extension on Ref {
|
||||
// We can move the previous logic to a Ref extension.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue