[Android] MediaparsingService: Fix actors
Geoffrey Métais
git at videolan.org
Tue Feb 11 10:08:09 CET 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 10 16:54:03 2020 +0100| [acfbc0520362d590c5dbe9af1b291bc9e55a1cb3] | committer: Nicolas Pomepuy
MediaparsingService: Fix actors
Recreate actors for every new lifecycle
> https://code.videolan.org/videolan/vlc-android/commit/acfbc0520362d590c5dbe9af1b291bc9e55a1cb3
---
.../src/org/videolan/vlc/MediaParsingService.kt | 26 +++++++++++++---------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 162491772..7c3adf8b1 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -38,7 +38,9 @@ import android.util.Log
import androidx.core.content.ContextCompat
import androidx.lifecycle.*
import kotlinx.coroutines.*
+import kotlinx.coroutines.channels.ActorScope
import kotlinx.coroutines.channels.Channel
+import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.channels.actor
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.MLServiceLocator
@@ -84,15 +86,8 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb, LifecycleOwn
private var discoverTriggered = false
internal val sb = StringBuilder()
val indexingListeners : List<IndexingListener> = AppContextProvider.indexingListeners
-
- private val notificationActor by lazy {
- lifecycleScope.actor<Notification>(capacity = Channel.UNLIMITED) {
- for (update in channel) when (update) {
- Show -> showNotification()
- Hide -> hideNotification()
- }
- }
- }
+ private lateinit var actions : SendChannel<MLAction>
+ private lateinit var notificationActor : SendChannel<Notification>
private val exceptionHandler = if (BuildConfig.BETA) Medialibrary.MedialibraryExceptionHandler { context, errMsg, _ ->
val intent = Intent(applicationContext, SendCrashActivity::class.java).apply {
@@ -145,6 +140,17 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb, LifecycleOwn
}
})
medialibrary.exceptionHandler = exceptionHandler
+ setupScope()
+ }
+
+ private fun setupScope() {
+ actions = lifecycleScope.actor(context = Dispatchers.IO, capacity = Channel.UNLIMITED) { processAction() }
+ notificationActor = lifecycleScope.actor(capacity = Channel.UNLIMITED) {
+ for (update in channel) when (update) {
+ Show -> showNotification()
+ Hide -> hideNotification()
+ }
+ }
}
override fun onBind(intent: Intent): IBinder? {
@@ -419,7 +425,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb, LifecycleOwn
progress.value = if (status === null) ScanProgress(parsing, discovery) else status.copy(parsing = parsing, discovery = discovery)
}
- private val actions = lifecycleScope.actor<MLAction>(context = Dispatchers.IO, capacity = Channel.UNLIMITED) {
+ private suspend fun ActorScope<MLAction>.processAction() {
for (action in channel) when (action) {
is DiscoverStorage -> {
for (folder in Medialibrary.getBlackList()) medialibrary.banFolder(action.path + folder)
More information about the Android
mailing list