[Android] libvlc: MediaPlayer: post a surface update after vout events
Alexandre Janniaux
git at videolan.org
Thu Jul 30 16:55:28 CEST 2020
vlc-android | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Jul 29 11:08:46 2020 +0200| [9bb29c3cbc819118d985b656ba074e814df24e2b] | committer: Alexandre Janniaux
libvlc: MediaPlayer: post a surface update after vout events
At least with LibVLC 4, the video surface stays black until the
orientation of the phone is changed, calling this event again after the
creation of the VLC vout display.
It might come from a wrong ordering and reporting of parent layout
events while the inner views are not reading for display, so post an
event at the end of the current mainloop re-updating the surfaces to be
sure that the video surface is visible in LibVLC client applications.
This a hack, but it is what the VLC for Android application is currently
doing too.
Refs #1433
> https://code.videolan.org/videolan/vlc-android/commit/9bb29c3cbc819118d985b656ba074e814df24e2b
---
libvlc/src/org/videolan/libvlc/MediaPlayer.java | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 0700216a0..6b41e9876 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -35,6 +35,8 @@ import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.util.SparseArray;
+import android.os.Handler;
+import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -583,6 +585,12 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
mAudioPlugRegistered = register;
}
+ /**
+ * HACK: handler to call updateVideoSurfaces() as soon as a video output
+ * is created. It is currently mandatory to have the video being displayed
+ * instead of a black screen. */
+ Handler mHandlerMainThread = new Handler(Looper.getMainLooper());
+
/**
* Create an empty MediaPlayer
*
@@ -1352,6 +1360,17 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
case Event.Vout:
mVoutCount = (int) arg1;
notify();
+
+ /* Post on the main thread so that surfaces gets updated
+ * after the event has been processed by the application.
+ * FIXME: This is a hack to ensure the video surface is
+ * correctly setup and doesn't appear black when using
+ * libvlcjni. */
+ mHandlerMainThread.post(new Runnable() {
+ @Override
+ public void run() { updateVideoSurfaces(); }
+ });
+
return new Event(eventType, arg1);
case Event.ESAdded:
case Event.ESDeleted:
More information about the Android
mailing list