[Android] Fix external device not added to medialibrary

Geoffrey Métais git at videolan.org
Thu Mar 14 15:39:38 CET 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 14 15:24:47 2019 +0100| [a4ccfb59495859e47b00028818426c9273ffb837] | committer: Geoffrey Métais

Fix external device not added to medialibrary

Fix #781

(cherry picked from commit 1e16da1920cd7c3442b4d41e9ad86d1c9d528cda)

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

 .../src/org/videolan/vlc/util/Kextensions.kt        | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index ffd9f0899..027c79d0e 100644
--- a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -78,17 +78,20 @@ fun Long.random() = (Random().nextFloat() * this).toLong()
 suspend inline fun <reified T> Context.getFromMl(crossinline block: Medialibrary.() -> T) = withContext(Dispatchers.IO) {
     val ml = Medialibrary.getInstance()
     if (ml.isStarted) block.invoke(ml)
-    else suspendCancellableCoroutine { continuation ->
-        val listener = object : Medialibrary.OnMedialibraryReadyListener {
-            override fun onMedialibraryReady() {
-                if (!continuation.isCompleted) continuation.resume(block.invoke(ml))
-                let { launch { ml.removeOnMedialibraryReadyListener(it) } }
+    else {
+        val scan = Settings.getInstance(this at getFromMl).getInt(KEY_MEDIALIBRARY_SCAN, ML_SCAN_ON) == ML_SCAN_ON
+        suspendCancellableCoroutine { continuation ->
+            val listener = object : Medialibrary.OnMedialibraryReadyListener {
+                override fun onMedialibraryReady() {
+                    if (!continuation.isCompleted) continuation.resume(block.invoke(ml))
+                    let { launch { ml.removeOnMedialibraryReadyListener(it) } }
+                }
+                override fun onMedialibraryIdle() {}
             }
-            override fun onMedialibraryIdle() {}
+            continuation.invokeOnCancellation { ml.removeOnMedialibraryReadyListener(listener) }
+            ml.addOnMedialibraryReadyListener(listener)
+            startMedialibrary(false, false, scan)
         }
-        continuation.invokeOnCancellation { ml.removeOnMedialibraryReadyListener(listener) }
-        ml.addOnMedialibraryReadyListener(listener)
-        startMedialibrary(false, false, false)
     }
 }
 



More information about the Android mailing list