[Android] Switch video player in PIP on multitasking

Geoffrey Métais git at videolan.org
Tue Jun 13 15:01:02 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jun 13 14:25:01 2017 +0200| [bfc60222bd83d299ae165b2de811c55b79173adb] | committer: Geoffrey Métais

Switch video player in PIP on multitasking

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

 .../vlc/gui/video/VideoPlayerActivity.java         | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 47115def8..ede10384e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -23,6 +23,7 @@ package org.videolan.vlc.gui.video;
 import android.annotation.TargetApi;
 import android.app.Activity;
 import android.app.KeyguardManager;
+import android.app.PictureInPictureParams;
 import android.app.Presentation;
 import android.bluetooth.BluetoothA2dp;
 import android.bluetooth.BluetoothHeadset;
@@ -47,6 +48,7 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
+import android.os.PowerManager;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
@@ -67,6 +69,7 @@ import android.text.TextUtils;
 import android.text.format.DateFormat;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.util.Rational;
 import android.view.Display;
 import android.view.GestureDetector;
 import android.view.InputDevice;
@@ -598,8 +601,31 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             mSize.setOnClickListener(null);
 
         /* Stop the earliest possible to avoid vout error */
-        if (!isInPictureInPictureMode() && (isFinishing() || (AndroidDevices.isAndroidTv() && !requestVisibleBehind(true))))
-            stopPlayback();
+
+        if (!isInPictureInPictureMode()) {
+            if (isFinishing() ||
+                    (AndroidUtil.isNougatOrLater && !AndroidUtil.isOOrLater //Video on background on Nougat Android TVs
+                            && AndroidDevices.isAndroidTv() && !requestVisibleBehind(true)))
+                stopPlayback();
+            else if (AndroidUtil.isOOrLater && mSettings.getBoolean("video_home_pip", false) && isInteractive()) {
+                enterPictureInPictureMode();
+            }
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    @Override
+    public void enterPictureInPictureMode() {
+        if (AndroidUtil.isOOrLater)
+            enterPictureInPictureMode(new PictureInPictureParams.Builder().setAspectRatio(new Rational(mVideoWidth, mVideoHeight)).build());
+        else
+            super.enterPictureInPictureMode();
+    }
+
+    @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
+    private boolean isInteractive() {
+        PowerManager pm = (PowerManager) VLCApplication.getAppContext().getSystemService(Context.POWER_SERVICE);
+        return AndroidUtil.isKitKatOrLater ? pm.isInteractive() : pm.isScreenOn();
     }
 
     @Override



More information about the Android mailing list