Skip to content

Commit

Permalink
fix: local tracks getting fetched on first load
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jun 17, 2023
1 parent ea45c4f commit 73c012c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/components/library/user_local_tracks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
40 changes: 24 additions & 16 deletions lib/provider/proxy_playlist/proxy_playlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -218,29 +218,37 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
bool autoPlay = false,
}) async {
tracks = blacklist.filter(tracks).toList() as List<Track>;
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<void> jumpTo(int index) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/audio_services/linux_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}),
Expand Down

0 comments on commit 73c012c

Please sign in to comment.