[Android] Network browsing: stop discovery on UI STOP state

Geoffrey Métais git at videolan.org
Mon Sep 23 18:10:50 CEST 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Sep 17 11:37:28 2019 +0200| [94f8d86554cbaf9764e601331046a591b0fb6ed8] | committer: Geoffrey Métais

Network browsing: stop discovery on UI STOP state

(cherry picked from commit 9c0b9389076528e042154c46711aa13608b7e88c)

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

 vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index 7acc98985..6fb60bdcc 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -58,6 +58,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
 
     protected var mediabrowser: MediaBrowser? = null
     private var parsingJob : Job? = null
+    private var discoveryJob : Job? = null
 
     private val foldersContentMap = SimpleArrayMap<MediaLibraryItem, MutableList<MediaLibraryItem>>()
     private val showAll = Settings.getInstance(context).getBoolean("browser_show_all_files", true)
@@ -121,9 +122,9 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
 
     protected open suspend fun browseImpl(url: String? = null) {
         if (url == null) {
-            filesFlow(url).collect { findMedia(it)?.let { addMedia(it) } }
-            if (dataset.value.isNotEmpty()) parseSubDirectories()
-            else dataset.clear() // send observable event when folder is empty
+            coroutineScope {
+                discoveryJob = launch { filesFlow(url).collect { findMedia(it)?.let { item -> addMedia(item) } } }
+            }
         } else {
             val value = filesFlow(url).mapNotNull { findMedia(it) }.toList()
             computeHeaders(value)
@@ -272,6 +273,8 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
 
     open fun stop() {
         browserActor.offer(Release)
+        discoveryJob?.cancel()
+        discoveryJob = null
         parsingJob?.cancel()
         parsingJob = null
     }



More information about the Android mailing list