[Android] Support Picture-in-Picture on Chrome OS

Kazuki Takise git at videolan.org
Mon Jan 13 15:54:15 CET 2020


vlc-android | branch: 3.2.x | Kazuki Takise <takise at google.com> | Thu Dec 26 16:10:03 2019 +0900| [a5b8465ea81c275d8f1dbe41a5175f1bdae2a362] | committer: Geoffrey Métais

Support Picture-in-Picture on Chrome OS

enterPictureInPictureMode() must be called in onUserLeaveHint() to
support Picture-in-Picture in a multi-window environment such as
Chrome OS.

The current implemententation (calling the API in onPause()) causes
the following issues on Chrome OS:

- VLC enters PiP without being occluded, but just with another
  window activated. In a multi-window environment, we can't assume
  onPause() means the window gets hidden. As only one window can
  be resumed at the same time, it's possible that a window is
  fully visible, but paused.
- When some ChromeOS-specific system UI gets shown (e.g. Alt-Tab
  window cycler, Overview Mode), VLC enters PiP unexpectedly.

This patch moves switchToPopup() from onPause() to onUserLeaveHint()
to prevent those issues.

(cherry picked from commit f466ecb066841924e1291cfcb11b83d3afa47b65)

> https://code.videolan.org/videolan/vlc-android/commit/a5b8465ea81c275d8f1dbe41a5175f1bdae2a362
---

 .../org/videolan/vlc/gui/video/VideoPlayerActivity.kt | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 8e4d6944e..98c0bb5e5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -595,16 +595,17 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
 
         /* Stop the earliest possible to avoid vout error */
 
-        if (!isInPictureInPictureMode) {
-            if (finishing || (AndroidUtil.isNougatOrLater && !AndroidUtil.isOOrLater //Video on background on Nougat Android TVs
+        if (!isInPictureInPictureMode
+                && (finishing || (AndroidUtil.isNougatOrLater && !AndroidUtil.isOOrLater //Video on background on Nougat Android TVs
+                                  && AndroidDevices.isAndroidTv && !requestVisibleBehind(true))))
+            stopPlayback()
+    }
 
-                            && AndroidDevices.isAndroidTv && !requestVisibleBehind(true)))
-                stopPlayback()
-            else if (displayManager.isPrimary && !isShowingDialog && "2" == settings.getString(KEY_VIDEO_APP_SWITCH, "0")
-                    && isInteractive && service?.hasRenderer() == false) {
-                switchToPopup()
-            }
-        }
+    @TargetApi(Build.VERSION_CODES.O)
+    override fun onUserLeaveHint() {
+        if (!isInPictureInPictureMode && displayManager.isPrimary && !isShowingDialog &&
+                "2" == settings.getString(KEY_VIDEO_APP_SWITCH, "0") && isInteractive && service?.hasRenderer() == false)
+            switchToPopup()
     }
 
     override fun onSaveInstanceState(outState: Bundle) {



More information about the Android mailing list