fix: local tracks getting fetched on first load

This commit is contained in:
Kingkor Roy Tirtho 2023-06-17 10:17:54 +06:00
parent ea45c4f42a
commit 73c012c71a
3 changed files with 26 additions and 18 deletions

View File

@ -95,7 +95,7 @@ final localTracksProvider = FutureProvider<List<LocalTrack>>((ref) async {
return {"metadata": metadata, "file": f, "art": imageFile.path};
} catch (e, stack) {
if (e is FfiException) {
return {};
return {"file": f};
}
Catcher.reportCheckedError(e, stack);
return {};

View File

@ -22,7 +22,7 @@ import 'package:spotube/utils/type_conversion_utils.dart';
/// Things to implement:
/// * [x] Sponsor-Block skip
/// * [x] Prefetch next track as [SpotubeTrack] on 80% of current track
/// * [ ] Mixed Queue containing both [SpotubeTrack] and [LocalTrack]
/// * [x] Mixed Queue containing both [SpotubeTrack] and [LocalTrack]
/// * [ ] Modification of the Queue
/// * [x] Add track at the end
/// * [x] Add track at the beginning
@ -218,6 +218,15 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
bool autoPlay = false,
}) async {
tracks = blacklist.filter(tracks).toList() as List<Track>;
final indexTrack = tracks.elementAtOrNull(initialIndex) ?? tracks.first;
if (indexTrack is LocalTrack) {
state = state.copyWith(
tracks: tracks.toSet(),
active: initialIndex,
);
await notificationService.addTrack(indexTrack);
} else {
final addableTrack = await SpotubeTrack.fetchFromTrack(
tracks.elementAtOrNull(initialIndex) ?? tracks.first,
preferences,
@ -228,19 +237,18 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
tracks: mergeTracks([addableTrack], tracks),
active: initialIndex,
);
await notificationService.addTrack(addableTrack);
await storeTrack(
tracks.elementAt(initialIndex),
addableTrack,
);
}
await audioPlayer.openPlaylist(
state.tracks.map(makeAppropriateSource).toList(),
initialIndex: initialIndex,
autoPlay: autoPlay,
);
await storeTrack(
tracks.elementAt(initialIndex),
addableTrack,
);
}
Future<void> jumpTo(int index) async {

View File

@ -323,7 +323,7 @@ class _MprisMediaPlayer2Player extends DBusObject {
"xesam:url": DBusString(
playlist.activeTrack is SpotubeTrack
? (playlist.activeTrack as SpotubeTrack).ytUri
: playlist.activeTrack!.previewUrl!,
: playlist.activeTrack!.previewUrl ?? "",
),
"xesam:genre": const DBusString("Unknown"),
}),