Merge pull request #5797 from manish99verma/fix-default-quality-setting-for-shorts

fix: default quality setting should respect video aspect ratio
This commit is contained in:
Bnyro 2024-04-17 19:27:01 +02:00 committed by GitHub
commit 1ccde40e0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -117,6 +117,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.concurrent.Executors
import kotlin.math.abs
import kotlin.math.ceil
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class PlayerFragment : Fragment(), OnlinePlayerOptions {
@ -136,6 +137,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
private var channelId: String? = null
private var keepQueue = false
private var timeStamp = 0L
private var isShort = false
// data and objects stored for the player
private lateinit var exoPlayer: ExoPlayer
@ -922,7 +924,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
}
val videoStream = streams.videoStreams.firstOrNull()
val isShort = PlayingQueue.getCurrent()?.isShort == true ||
isShort = PlayingQueue.getCurrent()?.isShort == true ||
(videoStream?.height ?: 0) > (videoStream?.width ?: 0)
PlayingQueue.setOnQueueTapListener { streamItem ->
@ -1252,10 +1254,16 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
}
}
private fun setPlayerResolution(resolution: Int) {
private fun setPlayerResolution(resolution: Int, isSelectedByUser: Boolean = false) {
val transformedResolution = if (!isSelectedByUser && isShort) {
ceil(resolution * 16.0 / 9.0).toInt()
} else {
resolution
}
trackSelector.updateParameters {
setMaxVideoSize(Int.MAX_VALUE, resolution)
setMinVideoSize(Int.MIN_VALUE, resolution)
setMaxVideoSize(Int.MAX_VALUE, transformedResolution)
setMinVideoSize(Int.MIN_VALUE, transformedResolution)
}
}
@ -1433,7 +1441,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
}
) { which ->
val newResolution = resolutions[which].resolution
setPlayerResolution(newResolution)
setPlayerResolution(newResolution, true)
// save the selected resolution to update on fullscreen change
if (noFullscreenResolution != null && viewModel.isFullscreen.value != true) {