fix: ensure aspect ratio from video is handled in a coherent way (#4219)

* fix: ensure aspect ratio from video is handled in a coherent way
This commit is contained in:
Olivier Bouillet
2024-10-12 13:51:57 +02:00
committed by GitHub
parent 352dfbbc9b
commit a8d5841c7c
2 changed files with 15 additions and 23 deletions

View File

@@ -2,6 +2,7 @@ package com.brentvatne.exoplayer
import android.content.Context
import android.widget.FrameLayout
import androidx.media3.common.Format
import com.brentvatne.common.api.ResizeMode
import kotlin.math.abs
@@ -94,4 +95,12 @@ class AspectRatioFrameLayout(context: Context) : FrameLayout(context) {
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
)
}
fun updateAspectRatio(format: Format) {
// There are weird cases when video height and width did not change with rotation so we need change aspect ration to fix it
when (format.rotationDegrees) {
90, 270 -> videoAspectRatio = if (format.width == 0) 1f else (format.height * format.pixelWidthHeightRatio) / format.width
else -> videoAspectRatio = if (format.height == 0) 1f else (format.width * format.pixelWidthHeightRatio) / format.height
}
}
}