Skip to content

Commit 1dff9d8

Browse files
authored
Merge pull request #115 from Mudit200408/seekbar-sync-perf
perf(android): optimize seekbar sync and filter out trivial media progress updates
2 parents 429afd3 + 9409b53 commit 1dff9d8

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

app/src/main/java/com/sameerasw/airsync/service/MediaNotificationListener.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ class MediaNotificationListener : NotificationListenerService() {
6161
SyncManager.checkAndSyncDeviceStatus(context, forceSync = true)
6262
}
6363

64+
fun hasSignificantMediaChange(old: MediaInfo?, new: MediaInfo?): Boolean {
65+
if (old == null && new == null) return false
66+
if (old == null || new == null) return true
67+
return old.isPlaying != new.isPlaying ||
68+
old.title != new.title ||
69+
old.artist != new.artist ||
70+
old.albumArt != new.albumArt ||
71+
old.albumArtLite != new.albumArtLite ||
72+
old.durationMs != new.durationMs ||
73+
old.isBuffering != new.isBuffering ||
74+
old.likeStatus != new.likeStatus
75+
}
76+
6477
// In-memory cache of like status per track key
6578
private val likeStatusCache = LinkedHashMap<String, String>(32, 0.75f, true)
6679

@@ -472,7 +485,7 @@ class MediaNotificationListener : NotificationListenerService() {
472485
updateMediaInfo()
473486

474487
// If media info changed, trigger sync
475-
if (previousMediaInfo != currentMediaInfo) {
488+
if (hasSignificantMediaChange(previousMediaInfo, currentMediaInfo)) {
476489
Log.d(TAG, "Media info changed, triggering sync")
477490
SyncManager.onMediaStateChanged(this)
478491
}
@@ -527,7 +540,7 @@ class MediaNotificationListener : NotificationListenerService() {
527540
updateMediaInfo()
528541

529542
// If media info changed, trigger sync
530-
if (previousMediaInfo != currentMediaInfo) {
543+
if (hasSignificantMediaChange(previousMediaInfo, currentMediaInfo)) {
531544
Log.d(TAG, "Media info changed after notification removal, triggering sync")
532545
SyncManager.onMediaStateChanged(this)
533546
}

0 commit comments

Comments
 (0)