fun calculateSurfaceSize()

in playerdemo/src/main/java/com/amazonaws/ivs/playerdemo/common/PlayerExtensions.kt [81:92]


fun calculateSurfaceSize(surfaceWidth: Int, surfaceHeight: Int, videoWidth: Int, videoHeight: Int): Pair<Int, Int> {
    val ratioHeight = videoHeight.toFloat() / videoWidth.toFloat()
    val ratioWidth = videoWidth.toFloat() / videoHeight.toFloat()
    val isPortrait = videoWidth < videoHeight
    val calculatedHeight = if (isPortrait) (surfaceWidth / ratioWidth).toInt() else (surfaceWidth * ratioHeight).toInt()
    val calculatedWidth = if (isPortrait) (surfaceHeight / ratioHeight).toInt() else (surfaceHeight * ratioWidth).toInt()
    return if (calculatedWidth >= surfaceWidth) {
        Pair(calculatedWidth, surfaceHeight)
    } else {
        Pair(surfaceWidth, calculatedHeight)
    }
}