[Android] Browser: Lift flow channel buffer limitation

Geoffrey Métais git at videolan.org
Tue Dec 10 10:07:03 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey at videolan.org> | Tue Dec 10 10:07:02 2019 +0100| [d5392279b294931b10c92722f095ddad0a1512d1] | committer: Nicolas Pomepuy

Browser: Lift flow channel buffer limitation

Fix #1117

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

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

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index e6d0335a6..7c767df19 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -31,10 +31,7 @@ import kotlinx.coroutines.channels.Channel
 import kotlinx.coroutines.channels.SendChannel
 import kotlinx.coroutines.channels.actor
 import kotlinx.coroutines.channels.awaitClose
-import kotlinx.coroutines.flow.channelFlow
-import kotlinx.coroutines.flow.collect
-import kotlinx.coroutines.flow.mapNotNull
-import kotlinx.coroutines.flow.toList
+import kotlinx.coroutines.flow.*
 import org.videolan.libvlc.Media
 import org.videolan.libvlc.util.MediaBrowser
 import org.videolan.libvlc.util.MediaBrowser.EventListener
@@ -123,10 +120,10 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
         if (url == null) coroutineScope {
             discoveryJob = launch { filesFlow(url).collect { findMedia(it)?.let { item -> addMedia(item) } } }
         } else {
-            val value = filesFlow(url).mapNotNull { findMedia(it) }.toList()
-            computeHeaders(value)
-            dataset.value = value as MutableList<MediaLibraryItem>
-            parseSubDirectories(value)
+            val files = filesFlow(url).mapNotNull { findMedia(it) }.toList()
+            computeHeaders(files)
+            dataset.value = files as MutableList<MediaLibraryItem>
+            parseSubDirectories(files)
         }
         if (url != null ) loading.postValue(false)
     }
@@ -145,7 +142,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
         }
         requestBrowsing(url, listener, interact)
         awaitClose { if (url != null) browserActor.post(ClearListener) }
-    }
+    }.buffer(Channel.UNLIMITED)
 
     protected open fun addMedia(media: MediaLibraryItem) = dataset.add(media)
 



More information about the Android mailing list