Skip to content

Commit

Permalink
update media notification when toggling track favorite status
Browse files Browse the repository at this point in the history
- fixes #989
  • Loading branch information
Chaphasilor committed Jan 24, 2025
1 parent 33958c8 commit d0c87ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/services/favorite_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:finamp/services/music_player_background_task.dart';
import 'package:finamp/services/queue_service.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_vibrate/flutter_vibrate.dart';
import 'package:get_it/get_it.dart';
Expand Down Expand Up @@ -77,6 +79,8 @@ class IsFavorite extends _$IsFavorite {
assert(value.item != null);
final isOffline = FinampSettingsHelper.finampSettings.isOffline;
final jellyfinApiHelper = GetIt.instance<JellyfinApiHelper>();
final audioHandler = GetIt.instance<MusicPlayerBackgroundTask>();
final queueService = GetIt.instance<QueueService>();
if (isOffline) {
FeedbackHelper.feedback(FeedbackType.error);
GlobalSnackbar.message(
Expand Down Expand Up @@ -108,6 +112,10 @@ class IsFavorite extends _$IsFavorite {
}
});
state = isFavorite;
// If the current track is the one being toggled, update the playback state (and media notification)
if (value.item!.id == queueService.getCurrentTrack()?.baseItem?.id) {
audioHandler.refreshPlaybackStateAndMediaNotification();
}
return state;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/services/favorite_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions lib/services/music_player_background_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,7 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler {
},
));
}
// re-trigger the playbackState update to update the notification
final event = _transformEvent(_player.playbackEvent);
return playbackState.add(event);
return refreshPlaybackStateAndMediaNotification();
default:
// NOP, handled below
}
Expand All @@ -709,6 +707,12 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler {
return await super.customAction(name, extras);
}

Future<void> refreshPlaybackStateAndMediaNotification() async {
// re-trigger the playbackState update to update the notification
final event = _transformEvent(_player.playbackEvent);
return playbackState.add(event);
}

// triggers when skipping to specific item in android auto queue
@override
Future<void> skipToQueueItem(int index) async {
Expand Down

0 comments on commit d0c87ee

Please sign in to comment.