[Android] MediaParsingService: add delay before service kill

Duncan McNamara git at videolan.org
Tue Apr 19 08:46:38 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Fri Apr 15 17:16:46 2022 +0200| [3a4eb37f20b8f1969811b52d8dd73becffa212d8] | committer: Nicolas Pomepuy

MediaParsingService: add delay before service kill

In some discovery cases, the medialibrary will internally switch
isWorking to false, before enqueuing another operation. This means that
the service, that has a listener on isWorking, will stop itself, and wont
get any updates on the operation that the medialibrary enqueued. To
conter this, a delay is added, afterwhich the isWorking value is checked
again before killing the service. If at that point the medialibrary is
working, then the service wont commit suicide, and the ui can get
progress updates.

> https://code.videolan.org/videolan/vlc-android/commit/3a4eb37f20b8f1969811b52d8dd73becffa212d8
---

 .../vlc-android/src/org/videolan/vlc/MediaParsingService.kt       | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 08f70562c..29a0169fe 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -134,8 +134,12 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
 
         if (lastNotificationTime == 5L) stopService(Intent(applicationContext, MediaParsingService::class.java))
         Medialibrary.getState().observe(this) { running ->
-            if (!running) {
-                exitCommand()
+            lifecycleScope.launch {
+                if (!running) {
+                    delay(1000L)
+                    if (!medialibrary.isWorking)
+                        exitCommand()
+                }
             }
         }
         medialibrary.exceptionHandler = exceptionHandler



More information about the Android mailing list