[Android] TV channel: wait for video surface to be ready
Geoffrey Métais
git at videolan.org
Mon May 27 16:23:37 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 27 16:15:36 2019 +0200| [0af348a1cb3542444c5ef3ff08d94cb5bd99faf7] | committer: Geoffrey Métais
TV channel: wait for video surface to be ready
> https://code.videolan.org/videolan/vlc-android/commit/0af348a1cb3542444c5ef3ff08d94cb5bd99faf7
---
vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt b/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt
index 839324cbc..a74ebfc12 100644
--- a/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt
+++ b/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt
@@ -55,6 +55,7 @@ class PreviewVideoInputService : TvInputService(), CoroutineScope {
val media = Media(VLCInstance.get(this at PreviewVideoInputService), mw.uri)
val start = if (mw.length <= 0L) 0L else mw.length.random()
media.addOption(":start-time=${start/1000L}")
+ awaitSurface()
player.getVout()?.apply {
setVideoSurface(surface, null)
attachViews(null)
@@ -78,9 +79,11 @@ class PreviewVideoInputService : TvInputService(), CoroutineScope {
private var width = 0
private var height = 0
private lateinit var surface: Surface
+ private var surfaceReady : CompletableDeferred<Unit>? = null
override fun onSetSurface(surface: Surface?): Boolean {
if (surface == null) return false
this.surface = surface
+ surfaceReady?.complete(Unit)
return true
}
@@ -98,5 +101,13 @@ class PreviewVideoInputService : TvInputService(), CoroutineScope {
MediaPlayer.Event.EndReached -> player.release()
}
}
+
+ private suspend fun awaitSurface() {
+ if (!::surface.isInitialized) {
+ surfaceReady = CompletableDeferred(Unit)
+ surfaceReady?.await()
+ surfaceReady = null
+ }
+ }
}
}
\ No newline at end of file
More information about the Android
mailing list