From f173ffa9725a772c0748b89a38ec04b7d848d053 Mon Sep 17 00:00:00 2001 From: klhyun Date: Fri, 16 Jul 2021 11:55:16 +0100 Subject: [PATCH] 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 --- .../java/com/google/android/exoplayer2/ui/PlayerView.java | 5 +++-- .../com/google/android/exoplayer2/ui/StyledPlayerView.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java index 2842c4440f..4241816db2 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java @@ -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; diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java index 16ef0894e5..0d4826daf0 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java @@ -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;