mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
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:
parent
626c3e9843
commit
f173ffa972
@ -1304,11 +1304,12 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
int height = videoSize.height;
|
int height = videoSize.height;
|
||||||
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
|
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
|
||||||
float videoAspectRatio =
|
float videoAspectRatio =
|
||||||
(height == 0 || width == 0) ? 1 : (width * videoSize.pixelWidthHeightRatio) / height;
|
(height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
|
||||||
|
|
||||||
if (surfaceView instanceof TextureView) {
|
if (surfaceView instanceof TextureView) {
|
||||||
// Try to apply rotation transformation when our surface is a 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.
|
// 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.
|
// In this case, the output video's width and height will be swapped.
|
||||||
videoAspectRatio = 1 / videoAspectRatio;
|
videoAspectRatio = 1 / videoAspectRatio;
|
||||||
|
@ -1455,11 +1455,12 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
int height = videoSize.height;
|
int height = videoSize.height;
|
||||||
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
|
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
|
||||||
float videoAspectRatio =
|
float videoAspectRatio =
|
||||||
(height == 0 || width == 0) ? 1 : (width * videoSize.pixelWidthHeightRatio) / height;
|
(height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
|
||||||
|
|
||||||
if (surfaceView instanceof TextureView) {
|
if (surfaceView instanceof TextureView) {
|
||||||
// Try to apply rotation transformation when our surface is a 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.
|
// 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.
|
// In this case, the output video's width and height will be swapped.
|
||||||
videoAspectRatio = 1 / videoAspectRatio;
|
videoAspectRatio = 1 / videoAspectRatio;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user