[Android] Unset renderer when connection is lost

Geoffrey Métais git at videolan.org
Thu Feb 28 15:15:53 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 28 14:29:27 2019 +0100| [878788e9e24e34c27e2ff1c10efc5925cf2165a9] | committer: Geoffrey Métais

Unset renderer when connection is lost

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

 vlc-android/src/org/videolan/vlc/RendererDelegate.kt | 12 +++++-------
 vlc-android/src/org/videolan/vlc/util/Kextensions.kt |  7 +++----
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/RendererDelegate.kt b/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
index d17aeb4ed..798c5c56b 100644
--- a/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
@@ -19,17 +19,14 @@
  */
 package org.videolan.vlc
 
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
+import kotlinx.coroutines.*
 import org.videolan.libvlc.RendererDiscoverer
 import org.videolan.libvlc.RendererItem
-import org.videolan.vlc.util.AppScope
-import org.videolan.vlc.util.LiveDataset
-import org.videolan.vlc.util.VLCInstance
-import org.videolan.vlc.util.retry
+import org.videolan.vlc.util.*
 import java.util.*
 
+ at ObsoleteCoroutinesApi
+ at ExperimentalCoroutinesApi
 object RendererDelegate : RendererDiscoverer.EventListener {
 
     private val TAG = "VLC/RendererDelegate"
@@ -58,6 +55,7 @@ object RendererDelegate : RendererDiscoverer.EventListener {
         if (!started) return
         started = false
         for (discoverer in discoverers) discoverer.stop()
+        if (isAppStarted()) PlaybackService.renderer.value = null
         clear()
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index f16a92550..7f5c79e39 100644
--- a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -10,10 +10,7 @@ import androidx.core.widget.TextViewCompat
 import androidx.databinding.BindingAdapter
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.FragmentActivity
-import androidx.lifecycle.LiveData
-import androidx.lifecycle.MediatorLiveData
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProviders
+import androidx.lifecycle.*
 import androidx.preference.PreferenceManager
 import kotlinx.coroutines.*
 import org.videolan.libvlc.Media
@@ -149,3 +146,5 @@ fun asyncText(view: TextView, text: CharSequence?) {
     val params = TextViewCompat.getTextMetricsParams(view)
     (view as AppCompatTextView).setTextFuture(PrecomputedTextCompat.getTextFuture(text, params, null))
 }
+
+fun isAppStarted() = ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)



More information about the Android mailing list