[Android] Video player: Fix PiP aspect ratio

Geoffrey Métais git at videolan.org
Wed Dec 4 13:36:59 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey at videolan.org> | Wed Dec  4 13:36:59 2019 +0100| [2d1c3754c4bda49e1c0c9740c896ba2d24765ca5] | committer: Nicolas Pomepuy

Video player: Fix PiP aspect ratio

Fix #1105

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

 .../org/videolan/vlc/gui/video/VideoPlayerActivity.kt   | 17 +++++------------
 1 file changed, 5 insertions(+), 12 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 03fd6358f..2626fb256 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -625,19 +625,13 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
             if (AndroidDevices.hasPiP && !forceLegacy) {
                 if (AndroidUtil.isOOrLater)
                     try {
-                        videoLayout?.findViewById<View>(R.id.surface_video)?.run {
-                            val height = if (height != 0) height else mw.height
-                            val width = Math.min(if (width != 0) width else mw.width, (height * 2.39f).toInt())
-                            enterPictureInPictureMode(PictureInPictureParams.Builder().setAspectRatio(Rational(width, height)).build())
-                        }
+                        val track = service?.playlistManager?.player?.mediaplayer?.currentVideoTrack ?: return
+                        val ar = Rational(track.width.coerceAtMost((track.height * 2.39f).toInt()), track.height)
+                        enterPictureInPictureMode(PictureInPictureParams.Builder().setAspectRatio(ar).build())
                     } catch (e: IllegalArgumentException) { // Fallback with default parameters
-
                         enterPictureInPictureMode()
                     }
-                else {
-
-                    enterPictureInPictureMode()
-                }
+                else enterPictureInPictureMode()
             } else {
                 if (Permissions.canDrawOverlays(this)) {
                     switchingView = true
@@ -645,8 +639,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
                     if (service?.isPlaying != true) mw.addFlags(AbstractMediaWrapper.MEDIA_PAUSED)
                     cleanUI()
                     exitOK()
-                } else
-                    Permissions.checkDrawOverlaysPermission(this)
+                } else Permissions.checkDrawOverlaysPermission(this)
             }
         }
     }



More information about the Android mailing list