[Android] Retry renderers discoverers start if failed
Geoffrey Métais
git at videolan.org
Thu Feb 8 15:44:09 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 8 15:31:27 2018 +0100| [3e64b008185b45b5ebdde1304c23a79efc5535e7] | committer: Geoffrey Métais
Retry renderers discoverers start if failed
> https://code.videolan.org/videolan/vlc-android/commit/3e64b008185b45b5ebdde1304c23a79efc5535e7
---
vlc-android/src/org/videolan/vlc/RendererDelegate.kt | 5 +++--
.../videolan/vlc/util/{Extensions.kt => Kextensions.kt} | 15 ++++++++++++++-
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/RendererDelegate.kt b/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
index b6de114d8..f81d1adeb 100644
--- a/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
@@ -20,12 +20,13 @@
package org.videolan.vlc
import kotlinx.coroutines.experimental.CoroutineStart
+import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.launch
-import kotlinx.coroutines.experimental.android.UI
import org.videolan.libvlc.RendererDiscoverer
import org.videolan.libvlc.RendererItem
import org.videolan.vlc.util.VLCInstance
+import org.videolan.vlc.util.retry
import java.util.*
object RendererDelegate : RendererDiscoverer.EventListener, ExternalMonitor.NetworkObserver {
@@ -60,7 +61,7 @@ object RendererDelegate : RendererDiscoverer.EventListener, ExternalMonitor.Netw
val rd = RendererDiscoverer(libVlc, discoverer.name)
mDiscoverers.add(rd)
rd.setEventListener(this at RendererDelegate)
- rd.start()
+ retry { rd.start() }
}
}
diff --git a/vlc-android/src/org/videolan/vlc/util/Extensions.kt b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
similarity index 66%
rename from vlc-android/src/org/videolan/vlc/util/Extensions.kt
rename to vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 2ee8a1f44..ba47d0a7e 100644
--- a/vlc-android/src/org/videolan/vlc/util/Extensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -1,12 +1,13 @@
package org.videolan.vlc.util
+import kotlinx.coroutines.experimental.delay
import java.io.File
import java.net.URI
import java.net.URISyntaxException
import java.util.*
-public fun String.validateLocation(): Boolean {
+fun String.validateLocation(): Boolean {
var location = this
/* Check if the MRL contains a scheme */
if (!location.matches("\\w+://.+".toRegex())) location = "file://$location"
@@ -23,4 +24,16 @@ public fun String.validateLocation(): Boolean {
if (!f.isFile) return false
}
return true
+}
+
+suspend fun retry (
+ times: Int = 3,
+ delayTime: Long = 500L,
+ block: suspend () -> Boolean): Boolean
+{
+ repeat(times - 1) {
+ if (block()) return true
+ delay(delayTime)
+ }
+ return block() // last attempt
}
\ No newline at end of file
More information about the Android
mailing list