Skip to content
Snippets Groups Projects
Commit d5392279 authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Nicolas Pomepuy
Browse files

Browser: Lift flow channel buffer limitation

Fix #1117
parent 9a9687a0
No related branches found
No related tags found
1 merge request!350Browser: Lift flow channel buffer limitation
Pipeline #11645 passed with stage
in 4 minutes and 44 seconds
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment