From 73c012c71ab5050636f79e010d654b4390978ee7 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 17 Jun 2023 10:17:54 +0600 Subject: [PATCH] fix: local tracks getting fetched on first load --- lib/components/library/user_local_tracks.dart | 2 +- .../proxy_playlist_provider.dart | 40 +++++++++++-------- .../audio_services/linux_audio_service.dart | 2 +- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/components/library/user_local_tracks.dart b/lib/components/library/user_local_tracks.dart index 05e8a9219..2431956ed 100644 --- a/lib/components/library/user_local_tracks.dart +++ b/lib/components/library/user_local_tracks.dart @@ -95,7 +95,7 @@ final localTracksProvider = FutureProvider>((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 {}; diff --git a/lib/provider/proxy_playlist/proxy_playlist_provider.dart b/lib/provider/proxy_playlist/proxy_playlist_provider.dart index 2ed3567c0..166b40e99 100644 --- a/lib/provider/proxy_playlist/proxy_playlist_provider.dart +++ b/lib/provider/proxy_playlist/proxy_playlist_provider.dart @@ -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,29 +218,37 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier bool autoPlay = false, }) async { tracks = blacklist.filter(tracks).toList() as List; - final addableTrack = await SpotubeTrack.fetchFromTrack( - tracks.elementAtOrNull(initialIndex) ?? tracks.first, - preferences, - pipedClient, - ); + final indexTrack = tracks.elementAtOrNull(initialIndex) ?? tracks.first; - state = state.copyWith( - tracks: mergeTracks([addableTrack], tracks), - active: initialIndex, - ); + 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, + pipedClient, + ); - await notificationService.addTrack(addableTrack); + state = state.copyWith( + 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 jumpTo(int index) async { diff --git a/lib/services/audio_services/linux_audio_service.dart b/lib/services/audio_services/linux_audio_service.dart index b50e4ee4d..99d840a4a 100644 --- a/lib/services/audio_services/linux_audio_service.dart +++ b/lib/services/audio_services/linux_audio_service.dart @@ -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"), }),