From 6469fffd8fe4ffc404f4bc1e405c362ff7020827 Mon Sep 17 00:00:00 2001 From: bachinger Date: Wed, 24 May 2023 16:59:34 +0100 Subject: [PATCH] Keep aspect ratio of `PlayerView` when IDLE When the video renderer is disabled, the video size is set to 0/0 and sent to listeners. The `PlayerView` potentially still has the last frame displayed when the player is stopped or an error occurs. This may have the effect that the frame is displayed distorted. Not changing the aspect ratio when the video size arrives when the player is IDLE avoids the problem. In the case when playback starts again and the renderes is enabled, another video size is sent to the listener. #minor-release PiperOrigin-RevId: 534860889 --- libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java b/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java index d732c2a753..083599bd20 100644 --- a/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java +++ b/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java @@ -1602,6 +1602,10 @@ public class PlayerView extends FrameLayout implements AdViewProvider { @Override public void onVideoSizeChanged(VideoSize videoSize) { + if (videoSize.equals(VideoSize.UNKNOWN) + && (player == null || player.getPlaybackState() == Player.STATE_IDLE)) { + return; + } updateAspectRatio(); }