diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt index 0dbba778..ce783fa5 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt @@ -436,10 +436,6 @@ class VideoDetailView : ConstraintLayout { showChaptersUI(); }; - _layoutPlayerContainer.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom -> - onShouldEnterPictureInPictureChanged.emit() - } - _title.setOnLongClickListener { val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager; val clip = ClipData.newPlainText("Video Title", (it as TextView).text); @@ -2031,6 +2027,10 @@ class VideoDetailView : ConstraintLayout { videoTrackFormats.distinctBy { it.height }.sortedByDescending { it.height }, audioTrackFormats.distinctBy { it.bitrate }.sortedByDescending { it.bitrate }); } + + _layoutPlayerContainer.post { + onShouldEnterPictureInPictureChanged.emit() + } } private var _didTriggerDatasourceErrorCount = 0; @@ -2491,7 +2491,6 @@ class VideoDetailView : ConstraintLayout { } isPlaying = playing; - onShouldEnterPictureInPictureChanged.emit() updateTracker(lastPositionMilliseconds, playing, true); } @@ -2625,6 +2624,9 @@ class VideoDetailView : ConstraintLayout { setProgressBarOverlayed(false); } onFullscreenChanged.emit(fullscreen); + _layoutPlayerContainer.post { + onShouldEnterPictureInPictureChanged.emit() + } } private fun setCastEnabled(isCasting: Boolean) { @@ -2899,10 +2901,6 @@ class VideoDetailView : ConstraintLayout { } else { _layoutPlayerContainer.setPadding(0, 0, 0, 0); } - - _layoutPlayerContainer.post { - onShouldEnterPictureInPictureChanged.emit() - } } fun getPictureInPictureParams() : PictureInPictureParams { var videoSourceWidth = _player.exoPlayer?.player?.videoSize?.width ?: 0; @@ -2913,16 +2911,23 @@ class VideoDetailView : ConstraintLayout { videoSourceHeight = 9; } val aspectRatio = videoSourceWidth.toDouble() / videoSourceHeight; + val r = _player.getVideoRect() if(aspectRatio > 2.38) { videoSourceWidth = 16; videoSourceHeight = 9; + + // shrink the left and right equally to get the rect to be 16 by 9 aspect ratio + // we don't want a picture in picture mode that's more squashed than 16 by 9 + val targetWidth = r.height() * 16 / 9 + val shrinkAmount = (r.width() - targetWidth) / 2 + r.left += shrinkAmount + r.right -= shrinkAmount } else if(aspectRatio < 0.43) { videoSourceHeight = 16; videoSourceWidth = 9; } - val r = _player.getVideoRect() val playpauseAction = if(_player.playing) RemoteAction(Icon.createWithResource(context, R.drawable.ic_pause_notif), context.getString(R.string.pause), context.getString(R.string.pauses_the_video), MediaControlReceiver.getPauseIntent(context, 5)); else diff --git a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt index 0405c625..f6432752 100644 --- a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt +++ b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt @@ -500,7 +500,8 @@ class FutoVideoPlayer : FutoVideoPlayerBase { fun getVideoRect(): Rect { val r = Rect() - _videoView.getGlobalVisibleRect(r) + // this is the only way i could reliably get a reference to a view that matches perfectly with the video playback + _videoView.subtitleView?.getGlobalVisibleRect(r) return r }