fix(android): handle aspect ratio for rotated videos (#4000)

This commit is contained in:
Kamil Moskała 2024-07-15 10:15:29 +02:00 committed by GitHub
parent f82268be1b
commit 0a55ace0ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -235,8 +235,16 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
// get the first track of the group to identify aspect ratio // get the first track of the group to identify aspect ratio
Format format = group.getTrackFormat(0); Format format = group.getTrackFormat(0);
// 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 ! // 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); layout.setVideoAspectRatio(format.height == 0 ? 1 : (format.width * format.pixelWidthHeightRatio) / format.height);
}
}
return; return;
} }
} }