[Android] Publish state on playlist update

Robert Stone git at videolan.org
Tue Nov 2 12:55:17 UTC 2021


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sat Oct 23 20:37:13 2021 -0700| [4ab2e2bb10e443006cede424efed4eeabe6fdd7b] | committer: Nicolas Pomepuy

Publish state on playlist update

Fixes #2196

> https://code.videolan.org/videolan/vlc-android/commit/4ab2e2bb10e443006cede424efed4eeabe6fdd7b
---

 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt     | 13 ++++++-------
 .../src/org/videolan/vlc/media/PlaylistManager.kt           |  2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 0122a89b5..8871dcc1b 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -177,8 +177,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         when (event.type) {
             MediaPlayer.Event.Playing -> {
                 if (BuildConfig.DEBUG) Log.i(TAG, "MediaPlayer.Event.Playing")
-                executeUpdate()
-                publishState()
+                executeUpdate(true)
                 lastTime = getTime()
                 audioFocusHelper.changeAudioFocus(true)
                 if (!wakeLock.isHeld) wakeLock.acquire()
@@ -187,8 +186,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
             }
             MediaPlayer.Event.Paused -> {
                 if (BuildConfig.DEBUG) Log.i(TAG, "MediaPlayer.Event.Paused")
-                executeUpdate()
-                publishState()
+                executeUpdate(true)
                 showNotification()
                 if (wakeLock.isHeld) wakeLock.release()
             }
@@ -196,8 +194,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
             MediaPlayer.Event.LengthChanged -> {
                 lastChaptersCount = getChapters(-1)?.size ?: 0
                 if (lastLength == 0L) {
-                    executeUpdate()
-                    publishState()
+                    executeUpdate(true)
                 }
             }
             MediaPlayer.Event.PositionChanged -> {
@@ -740,11 +737,13 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
 
     fun onMediaEvent(event: IMedia.Event) = cbActor.safeOffer(CbMediaEvent(event))
 
-    fun executeUpdate() {
+    fun executeUpdate(pubState: Boolean = false) {
         cbActor.safeOffer(CbUpdate)
         updateWidget()
         updateMetadata()
         broadcastMetadata()
+        if (pubState)
+            publishState()
     }
 
     private class PlaybackServiceHandler(owner: PlaybackService) : WeakHandler<PlaybackService>(owner) {
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 ce8d5291c..5b0ab1e8d 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -493,7 +493,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     }
 
     private fun executeUpdate() {
-        service.executeUpdate()
+        service.executeUpdate(true)
     }
 
     fun saveMediaMeta() = launch(start = CoroutineStart.UNDISPATCHED) {



More information about the Android mailing list