[Android] Prevent the UI refresh when it's triggered by the playback saving meta data

Nicolas Pomepuy git at videolan.org
Tue May 16 08:35:52 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue May 16 08:13:10 2023 +0200| [654dc3623ca2228954c84887fd3fbc6a28e4a8f1] | committer: Duncan McNamara

Prevent the UI refresh when it's triggered by the playback saving meta data

Fixes #2936

> https://code.videolan.org/videolan/vlc-android/commit/654dc3623ca2228954c84887fd3fbc6a28e4a8f1
---

 .../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt    | 5 +++++
 .../src/org/videolan/vlc/viewmodels/CallBackDelegate.kt          | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 9fcbc8bd31..b42e3ba571 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -46,6 +46,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
     companion object {
         val showAudioPlayer = MutableLiveData<Boolean>().apply { value = false }
+        // The playback will periodically modify the media by saving its meta
+        // When playing audio, it will have no impact on UI but will trigger the media modified ML callback
+        // On slow devices, it will trigger an unwanted "refresh animation". This flag prevents it
+        var skipMediaUpdateRefresh = false
         private val mediaList = MediaWrapperList()
         fun hasMedia() = mediaList.size() != 0
     }
@@ -575,6 +579,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                         }
                     }
                 }
+            if (media.type != MediaWrapper.TYPE_VIDEO && !canSwitchToVideo && !media.isPodcast) skipMediaUpdateRefresh = true
             media.setStringMeta(MediaWrapper.META_SPEED, rate.toString())
 
         }
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt
index 3874c57523..92ab681695 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt
@@ -30,6 +30,7 @@ import kotlinx.coroutines.channels.actor
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.resources.AppContextProvider
 import org.videolan.tools.conflatedActor
+import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.util.FileUtils
 import java.io.File
 
@@ -195,7 +196,13 @@ class CallBackDelegate : ICallBackHandler,
 
     override fun onMediaAdded() { refreshActor.trySend(Unit) }
 
-    override fun onMediaModified() { refreshActor.trySend(Unit) }
+    override fun onMediaModified() {
+        if (PlaylistManager.skipMediaUpdateRefresh) {
+            PlaylistManager.skipMediaUpdateRefresh = false
+            return
+        }
+        refreshActor.trySend(Unit)
+    }
 
     override fun onMediaDeleted(ids: LongArray) {
         refreshActor.trySend(Unit)



More information about the Android mailing list