一堆乱七八糟的修改

播放页面增加桌面版
This commit is contained in:
rang 2025-11-28 17:05:35 +08:00
parent aee1fbde88
commit 3ba35b31b8
116 changed files with 1238 additions and 2592 deletions

View file

@ -0,0 +1,85 @@
import 'package:shelfsdk/audiobookshelf_api.dart';
/// will manage the playlist of items
///
/// you are responsible for updating the current index and sub index
class AudiobookPlaylist {
/// list of items in the playlist
final List<BookExpanded> books;
/// current index of the item in the playlist
int _currentIndex;
/// current index of the audio file in the current item
int _subCurrentIndex;
// wrappers for adding and removing items
void add(BookExpanded item) => books.add(item);
void remove(BookExpanded item) => books.remove(item);
void clear() {
books.clear();
_currentIndex = 0;
_subCurrentIndex = 0;
}
// move an item from one index to another
void move(int from, int to) {
final item = books.removeAt(from);
books.insert(to, item);
}
/// the book being played
BookExpanded? get currentBook {
if (_currentIndex >= books.length || _currentIndex < 0 || books.isEmpty) {
return null;
}
return books[_currentIndex];
}
/// of the book in the playlist
int get currentIndex => _currentIndex;
// every time current index changes, we need to update the sub index
set currentIndex(int index) {
// if the index is the same, do nothing
if (_currentIndex == index) {
return;
}
_currentIndex = index;
subCurrentIndex = 0;
}
/// of the audio file in the current book
int get subCurrentIndex => _subCurrentIndex;
set subCurrentIndex(int index) {
if (index < 0) {
index = 0;
}
_subCurrentIndex = index;
}
AudiobookPlaylist({
this.books = const [],
currentIndex = 0,
subCurrentIndex = 0,
}) : _currentIndex = currentIndex,
_subCurrentIndex = subCurrentIndex;
// most important method, gets the audio file to play
// this is needed as a library item is a list of audio files
AudioTrack? getAudioTrack() {
final book = currentBook;
if (book == null) {
return null;
}
if (subCurrentIndex > book.tracks.length || book.tracks.isEmpty) {
return null;
}
return book.tracks[subCurrentIndex];
}
bool get isBookFinished => subCurrentIndex >= currentBook!.tracks.length;
// a method to get the next audio file and advance the sub index
}

View file

@ -0,0 +1,18 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:shelfsdk/audiobookshelf_api.dart';
import 'package:vaani/features/playlist/playlist.dart';
part 'playlist_provider.g.dart';
@riverpod
class Playlist extends _$Playlist {
@override
AudiobookPlaylist build() {
return AudiobookPlaylist();
}
void add(BookExpanded item) {
state.add(item);
ref.notifyListeners();
}
}

View file

@ -0,0 +1,25 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'playlist_provider.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$playlistHash() => r'bed4642e4c2de829e4d0630cb5bf92bffeeb1f60';
/// See also [Playlist].
@ProviderFor(Playlist)
final playlistProvider =
AutoDisposeNotifierProvider<Playlist, AudiobookPlaylist>.internal(
Playlist.new,
name: r'playlistProvider',
debugGetCreateSourceHash:
const bool.fromEnvironment('dart.vm.product') ? null : _$playlistHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef _$Playlist = AutoDisposeNotifier<AudiobookPlaylist>;
// 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