[Android] Browser: ensure mediabrowser is released
Geoffrey Métais
git at videolan.org
Fri Jul 12 16:41:47 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul 12 16:38:35 2019 +0200| [ed36af286d1a299761db01df96277ed635b06132] | committer: Geoffrey Métais
Browser: ensure mediabrowser is released
See #923
> https://code.videolan.org/videolan/vlc-android/commit/ed36af286d1a299761db01df96277ed635b06132
---
.../src/org/videolan/vlc/providers/BrowserProvider.kt | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index 2addca2cf..6adf2ee74 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -62,17 +62,21 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
val descriptionUpdate = MutableLiveData<Pair<Int, String>>()
internal val medialibrary = AbstractMedialibrary.getInstance()
- private val browserActor = actor<BrowserAction>(capacity = Channel.UNLIMITED) {
+ private val completionHandler = object : CompletionHandler {
+ override fun invoke(cause: Throwable?) {
+ mediabrowser?.release()
+ mediabrowser = null
+ if (this at BrowserProvider::browserChannel.isInitialized) browserChannel.close()
+ }
+
+ }
+
+ private val browserActor = actor<BrowserAction>(capacity = Channel.UNLIMITED, onCompletion = completionHandler) {
for (action in channel) if (isActive) when (action) {
is Browse -> browseImpl(action.url)
BrowseRoot -> browseRootImpl()
Refresh -> refreshImpl()
ParseSubDirectories -> parseSubDirectoriesImpl()
- Release -> {
- mediabrowser?.release()
- mediabrowser = null
- if (this at BrowserProvider::browserChannel.isInitialized) browserChannel.close()
- }
ClearListener -> mediabrowser?.changeEventListener(null)
} else channel.close()
}
@@ -270,7 +274,6 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
protected fun clearListener() = browserActor.post(ClearListener)
open fun release() {
- browserActor.post(Release)
cancel()
loading.postValue(false)
}
@@ -301,4 +304,3 @@ private object BrowseRoot : BrowserAction()
private object Refresh : BrowserAction()
private object ParseSubDirectories : BrowserAction()
private object ClearListener : BrowserAction()
-private object Release : BrowserAction()
\ No newline at end of file
More information about the Android
mailing list