Skip to content

Commit

Permalink
Merge pull request #69 from android/pip-add-extension
Browse files Browse the repository at this point in the history
Clean up conditionals in PiP logic
  • Loading branch information
MagicalMeghan committed May 8, 2024
2 parents 5bffebb + 03f195d commit 042bb37
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import androidx.lifecycle.compose.LifecycleStartEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.media3.common.Player
import androidx.media3.common.VideoSize
import androidx.media3.ui.PlayerView
import com.google.android.samples.socialite.R

Expand Down Expand Up @@ -174,14 +175,12 @@ private fun VideoPlayer(
// create modifier that adds pip to video player
val pipModifier = modifier.onGloballyPositioned { layoutCoordinates ->
val builder = PictureInPictureParams.Builder()
if (shouldEnterPipMode) {
if (shouldEnterPipMode && player != null && player.videoSize != VideoSize.UNKNOWN) {
// 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)
}
val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect()
builder.setSourceRectHint(sourceRect)
val aspectRatio = Rational(player.videoSize.width, player.videoSize.height)
builder.setAspectRatio(aspectRatio)
}

builder.setActions(
Expand Down

0 comments on commit 042bb37

Please sign in to comment.