Skip to content
Snippets Groups Projects
Commit 3e64b008 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Retry renderers discoverers start if failed

parent dc8a3874
No related branches found
No related tags found
No related merge requests found
......@@ -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@RendererDelegate)
rd.start()
retry { rd.start() }
}
}
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment