diff --git a/app/src/main/java/com/google/android/samples/socialite/ui/player/VideoPlayerScreen.kt b/app/src/main/java/com/google/android/samples/socialite/ui/player/VideoPlayerScreen.kt index 225ec3f1..6260c2f4 100644 --- a/app/src/main/java/com/google/android/samples/socialite/ui/player/VideoPlayerScreen.kt +++ b/app/src/main/java/com/google/android/samples/socialite/ui/player/VideoPlayerScreen.kt @@ -174,12 +174,14 @@ private fun VideoPlayer( // create modifier that adds pip to video player val pipModifier = modifier.onGloballyPositioned { layoutCoordinates -> val builder = PictureInPictureParams.Builder() - if (shouldEnterPipMode) { - // set source rect hint, aspect ratio and remote actions - val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect() - builder.setSourceRectHint(sourceRect) - builder.setAspectRatio(Rational(sourceRect.width(), sourceRect.height())) + // set source rect hint, aspect ratio + if (player != null && player.videoSize.width > 0 && player.videoSize.height > 0) { + val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect() + builder.setSourceRectHint(sourceRect) + val aspectRatio = Rational(player.videoSize.width, player.videoSize.height) + builder.setAspectRatio(aspectRatio) + } } builder.setActions(