From bb006fd3cc2ac3f859239c453e626a4c2546dd4c Mon Sep 17 00:00:00 2001 From: Lars <129963861+Raasu258@users.noreply.github.com> Date: Mon, 31 Aug 2026 19:23:28 +0200 Subject: [PATCH] fix: await notification service before adding track to avoid race condition --- lib/provider/audio_player/audio_player_streams.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/provider/audio_player/audio_player_streams.dart b/lib/provider/audio_player/audio_player_streams.dart index eff13134..5f015053 100644 --- a/lib/provider/audio_player/audio_player_streams.dart +++ b/lib/provider/audio_player/audio_player_streams.dart @@ -19,11 +19,10 @@ import 'package:spotube/services/logger/logger.dart'; class AudioPlayerStreamListeners { final Ref ref; - late final AudioServices notificationService; + late final Future notificationServiceFuture; AudioPlayerStreamListeners(this.ref) { - AudioServices.create(ref, ref.read(audioPlayerProvider.notifier)).then( - (value) => notificationService = value, - ); + notificationServiceFuture = + AudioServices.create(ref, ref.read(audioPlayerProvider.notifier)); final subscriptions = [ subscribeToPlaylist(), @@ -48,10 +47,11 @@ class AudioPlayerStreamListeners { ref.read(playbackHistoryActionsProvider); StreamSubscription subscribeToPlaylist() { - return audioPlayer.playlistStream.listen((mpvPlaylist) { + return audioPlayer.playlistStream.listen((mpvPlaylist) async { try { if (audioPlayerState.activeTrack == null) return; - notificationService.addTrack(audioPlayerState.activeTrack!); + final notificationService = await notificationServiceFuture; + await notificationService.addTrack(audioPlayerState.activeTrack!); discord.updatePresence(audioPlayerState.activeTrack!); } catch (e, stack) { AppLogger.reportError(e, stack);