Do not set aspect ratio if unknown.

When the size of the video is unknown,
PlayerView and StyledPlayerView set the aspect ratio as 1,
which could result in wrong view layout.

This CL sets the aspect ratio as 0 (unset) to prevent that.

This handles Issue: #9189.

PiperOrigin-RevId: 385115357
This commit is contained in:
klhyun 2021-07-16 11:55:16 +01:00 committed by Ian Baker
parent 626c3e9843
commit f173ffa972
2 changed files with 6 additions and 4 deletions

View File

@ -1304,11 +1304,12 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
int height = videoSize.height;
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
float videoAspectRatio =
(height == 0 || width == 0) ? 1 : (width * videoSize.pixelWidthHeightRatio) / height;
(height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
if (surfaceView instanceof TextureView) {
// Try to apply rotation transformation when our surface is a TextureView.
if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
if (videoAspectRatio > 0
&& (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270)) {
// We will apply a rotation 90/270 degree to the output texture of the TextureView.
// In this case, the output video's width and height will be swapped.
videoAspectRatio = 1 / videoAspectRatio;

View File

@ -1455,11 +1455,12 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
int height = videoSize.height;
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
float videoAspectRatio =
(height == 0 || width == 0) ? 1 : (width * videoSize.pixelWidthHeightRatio) / height;
(height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
if (surfaceView instanceof TextureView) {
// Try to apply rotation transformation when our surface is a TextureView.
if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
if (videoAspectRatio > 0
&& (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270)) {
// We will apply a rotation 90/270 degree to the output texture of the TextureView.
// In this case, the output video's width and height will be swapped.
videoAspectRatio = 1 / videoAspectRatio;