Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PiP aspect ratio issue #57

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.ContextWrapper
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.util.Log
import android.util.Rational
import androidx.activity.ComponentActivity
import androidx.compose.foundation.focusable
Expand Down Expand Up @@ -179,7 +180,17 @@ private fun VideoPlayer(
// 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()))
var aspectRatio = Rational(sourceRect.width(), sourceRect.height())
val upperAspectRatioBound = Rational(2.39.toInt(), 1)
val lowerAspectRatioBound = Rational(1, 2.39.toInt())
MagicalMeghan marked this conversation as resolved.
Show resolved Hide resolved

if(aspectRatio.toFloat() > upperAspectRatioBound.toFloat()) {
aspectRatio = upperAspectRatioBound
} else if(aspectRatio.toFloat() < lowerAspectRatioBound.toFloat()) {
aspectRatio = lowerAspectRatioBound
}

builder.setAspectRatio(aspectRatio)
}

builder.setActions(
Expand Down
Loading