[Android] Medialibrary: Fix ConcurrentAccessException
Geoffrey Métais
git at videolan.org
Tue Jan 8 15:20:28 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan 8 15:19:46 2019 +0100| [8f010d12d01c2ca407b5a55d6cf723d1c2cbf564] | committer: Geoffrey Métais
Medialibrary: Fix ConcurrentAccessException
> https://code.videolan.org/videolan/vlc-android/commit/8f010d12d01c2ca407b5a55d6cf723d1c2cbf564
---
vlc-android/src/org/videolan/vlc/util/Kextensions.kt | 3 ++-
vlc-android/src/org/videolan/vlc/util/TvChannels.kt | 7 +++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 08cb3b47d..9eb1d43a1 100644
--- a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -73,8 +73,9 @@ suspend inline fun <reified T> Context.getFromMl(crossinline block: Medialibrary
else suspendCoroutine { continuation ->
ml.addOnMedialibraryReadyListener(object : Medialibrary.OnMedialibraryReadyListener {
override fun onMedialibraryReady() {
- ml.removeOnMedialibraryReadyListener(this)
+ val listener = this
continuation.resume(block.invoke(ml))
+ launch { ml.removeOnMedialibraryReadyListener(listener) }
}
override fun onMedialibraryIdle() {}
})
diff --git a/vlc-android/src/org/videolan/vlc/util/TvChannels.kt b/vlc-android/src/org/videolan/vlc/util/TvChannels.kt
index 851a461d2..0e1530d0e 100644
--- a/vlc-android/src/org/videolan/vlc/util/TvChannels.kt
+++ b/vlc-android/src/org/videolan/vlc/util/TvChannels.kt
@@ -60,8 +60,11 @@ suspend fun updatePrograms(context: Context, channelId: Long) {
ml.addOnMedialibraryReadyListener(object : Medialibrary.OnMedialibraryReadyListener {
override fun onMedialibraryIdle() {}
override fun onMedialibraryReady() {
- ml.removeOnMedialibraryReadyListener(this)
- GlobalScope.launch { updatePrograms(context, channelId) }
+ val listener = this
+ GlobalScope.launch {
+ ml.removeOnMedialibraryReadyListener(listener)
+ updatePrograms(context, channelId)
+ }
}
})
More information about the Android
mailing list