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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user