Prevent crash with PiP if asked aspect ratio is < 1/2.39 or > to 2.39
This commit is contained in:
parent
61454f5923
commit
a72ee81ec6
3 changed files with 26 additions and 8 deletions
|
@ -65,10 +65,14 @@ class Api26Compatibility {
|
|||
val params = PictureInPictureParams.Builder()
|
||||
.setAspectRatio(Compatibility.getPipRatio(activity, conference, !conference))
|
||||
.build()
|
||||
if (!activity.enterPictureInPictureMode(params)) {
|
||||
Log.e("[Call] Failed to enter PiP mode")
|
||||
} else {
|
||||
Log.i("[Call] Entering PiP mode with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
||||
try {
|
||||
if (!activity.enterPictureInPictureMode(params)) {
|
||||
Log.e("[Call] Failed to enter PiP mode")
|
||||
} else {
|
||||
Log.i("[Call] Entering PiP mode with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Call] Can't build PiP params: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,8 +215,12 @@ class Api31Compatibility {
|
|||
.setAutoEnterEnabled(enable)
|
||||
.setAspectRatio(Compatibility.getPipRatio(activity, conference, !conference))
|
||||
.build()
|
||||
activity.setPictureInPictureParams(params)
|
||||
Log.i("[Call] PiP auto enter enabled params set to $enable with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
||||
try {
|
||||
activity.setPictureInPictureParams(params)
|
||||
Log.i("[Call] PiP auto enter enabled params set to $enable with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Call] Can't build PiP params: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -287,8 +287,18 @@ class Compatibility {
|
|||
): Rational {
|
||||
val displayMetrics = DisplayMetrics()
|
||||
activity.windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
val height = displayMetrics.heightPixels
|
||||
val width = displayMetrics.widthPixels
|
||||
var height = displayMetrics.heightPixels
|
||||
var width = displayMetrics.widthPixels
|
||||
|
||||
val aspectRatio = width / height
|
||||
if (aspectRatio < 1 / 2.39) {
|
||||
height = 2.39.toInt()
|
||||
width = 1
|
||||
} else if (aspectRatio > 2.39) {
|
||||
width = 2.39.toInt()
|
||||
height = 1
|
||||
}
|
||||
|
||||
val ratio = if (width > height) {
|
||||
if (forcePortrait) {
|
||||
Rational(height, width)
|
||||
|
|
Loading…
Reference in a new issue