diff --git a/app/src/main/java/com/sameerasw/airsync/service/MediaNotificationListener.kt b/app/src/main/java/com/sameerasw/airsync/service/MediaNotificationListener.kt index ed8c31c5..51c1e765 100644 --- a/app/src/main/java/com/sameerasw/airsync/service/MediaNotificationListener.kt +++ b/app/src/main/java/com/sameerasw/airsync/service/MediaNotificationListener.kt @@ -61,6 +61,19 @@ class MediaNotificationListener : NotificationListenerService() { SyncManager.checkAndSyncDeviceStatus(context, forceSync = true) } + fun hasSignificantMediaChange(old: MediaInfo?, new: MediaInfo?): Boolean { + if (old == null && new == null) return false + if (old == null || new == null) return true + return old.isPlaying != new.isPlaying || + old.title != new.title || + old.artist != new.artist || + old.albumArt != new.albumArt || + old.albumArtLite != new.albumArtLite || + old.durationMs != new.durationMs || + old.isBuffering != new.isBuffering || + old.likeStatus != new.likeStatus + } + // In-memory cache of like status per track key private val likeStatusCache = LinkedHashMap(32, 0.75f, true) @@ -472,7 +485,7 @@ class MediaNotificationListener : NotificationListenerService() { updateMediaInfo() // If media info changed, trigger sync - if (previousMediaInfo != currentMediaInfo) { + if (hasSignificantMediaChange(previousMediaInfo, currentMediaInfo)) { Log.d(TAG, "Media info changed, triggering sync") SyncManager.onMediaStateChanged(this) } @@ -527,7 +540,7 @@ class MediaNotificationListener : NotificationListenerService() { updateMediaInfo() // If media info changed, trigger sync - if (previousMediaInfo != currentMediaInfo) { + if (hasSignificantMediaChange(previousMediaInfo, currentMediaInfo)) { Log.d(TAG, "Media info changed after notification removal, triggering sync") SyncManager.onMediaStateChanged(this) }