[Android] Retain and release current Renderer object

Geoffrey Métais git at videolan.org
Wed Mar 6 15:43:06 CET 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar  6 14:52:25 2019 +0100| [c7d60c0998e416ea76f566dd6d0cb661fb48166b] | committer: Geoffrey Métais

Retain and release current Renderer object

(cherry picked from commit 8e7183daa30531c77cca84a9a7ebb6986aab1fc6)

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

 vlc-android/src/org/videolan/vlc/PlaybackService.kt       |  4 ++--
 vlc-android/src/org/videolan/vlc/util/RendererLiveData.kt | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 3ece6518b..e36eb6208 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1280,7 +1280,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
 
     companion object {
         val service: LiveData<PlaybackService> = MutableLiveData<PlaybackService>()
-        val renderer = MutableLiveData<RendererItem>()
+        val renderer = RendererLiveData()
         val restartPlayer = LiveEvent<Boolean>()
         val headSetDetection = LiveEvent<Boolean>()
         val equalizer = LiveEvent<MediaPlayer.Equalizer>()
@@ -1321,4 +1321,4 @@ private class CbAdd(val cb : PlaybackService.Callback) : CbAction()
 private class CbRemove(val cb : PlaybackService.Callback) : CbAction()
 private object ShowNotification : CbAction()
 private class HideNotification(val remove: Boolean) : CbAction()
-private object UpdateMeta : CbAction()
\ No newline at end of file
+private object UpdateMeta : CbAction()
diff --git a/vlc-android/src/org/videolan/vlc/util/RendererLiveData.kt b/vlc-android/src/org/videolan/vlc/util/RendererLiveData.kt
new file mode 100644
index 000000000..2ce33c339
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/util/RendererLiveData.kt
@@ -0,0 +1,14 @@
+package org.videolan.vlc.util
+
+import androidx.lifecycle.MutableLiveData
+import org.videolan.libvlc.RendererItem
+
+
+class RendererLiveData : MutableLiveData<RendererItem>() {
+
+    override fun setValue(value: RendererItem?) {
+        getValue()?.release()
+        value?.retain()
+        super.setValue(value)
+    }
+}
\ No newline at end of file



More information about the Android mailing list