Commit f173ffa9 by klhyun Committed by Ian Baker

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
parent 626c3e98
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment