home_media_state.dart 1.1 KB

123456789101112131415161718192021222324252627
  1. import '../../core/app_identity.dart';
  2. import '../../data/models/media_playback.dart';
  3. /// Whether the current system media session belongs to another app.
  4. ///
  5. /// CarDash's own Jellyfin player also publishes a MediaSession. While Jellyfin
  6. /// pauses, the system snapshot can still report that session as playing for up
  7. /// to one poll (~900 ms), so it must not be treated as external music.
  8. bool isExternalSystemMedia(MediaPlayback media) {
  9. return media.packageName != appPackageName;
  10. }
  11. /// Whether the Music tile should show its animated equalizer.
  12. ///
  13. /// A Jellyfin pause updates the Jellyfin controller immediately, while the
  14. /// Android media snapshot can remain playing for one system poll. The Music
  15. /// tile must stay quiet during that gap instead of flashing until the next
  16. /// poll: if the active session is CarDash's own Jellyfin session, it is not
  17. /// another app's music.
  18. bool shouldShowMusicEqualizer({
  19. required bool systemMusicPlaying,
  20. required bool jellyfinPlaying,
  21. required MediaPlayback systemMedia,
  22. }) {
  23. if (!systemMusicPlaying || jellyfinPlaying) return false;
  24. return isExternalSystemMedia(systemMedia);
  25. }