From 0a55ace0ca92f56394235f7c651d3a160e6a3c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Moska=C5=82a?= <91079590+moskalakamil@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:15:29 +0200 Subject: [PATCH] fix(android): handle aspect ratio for rotated videos (#4000) --- .../java/com/brentvatne/exoplayer/ExoPlayerView.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java index ceec9965..d1ac5227 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java @@ -235,8 +235,16 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider { // get the first track of the group to identify aspect ratio Format format = group.getTrackFormat(0); - // update aspect ratio ! - layout.setVideoAspectRatio(format.height == 0 ? 1 : (format.width * format.pixelWidthHeightRatio) / format.height); + // There are weird cases when video height and width did not change with rotation so we need change aspect ration to fix it + switch (format.rotationDegrees) { + // update aspect ratio ! + case 90, 270 -> { + layout.setVideoAspectRatio(format.width == 0 ? 1 : (format.height * format.pixelWidthHeightRatio) / format.width); + } + default -> { + layout.setVideoAspectRatio(format.height == 0 ? 1 : (format.width * format.pixelWidthHeightRatio) / format.height); + } + } return; } }