[Android] TV channel: wait for video surface to be ready
Geoffrey Métais
git at videolan.org
Mon May 27 16:27:27 CEST 2019
vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 27 16:15:36 2019 +0200| [dbf31abfb537ff075f0ffd477bbbcffe6a6986de] | committer: Geoffrey Métais
TV channel: wait for video surface to be ready
(cherry picked from commit a49eb735be3c540d7651e440171c73e5c96830b4)
> https://code.videolan.org/videolan/vlc-android/commit/dbf31abfb537ff075f0ffd477bbbcffe6a6986de
---
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