Merge pull request #4296 from Bnyro/master

fix: fullscreen orientation after shorts video
This commit is contained in:
Bnyro 2023-07-24 13:35:35 +02:00 committed by GitHub
commit 24210a1eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -510,6 +510,21 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
NavigationHelper.startAudioPlayer(requireContext()) NavigationHelper.startAudioPlayer(requireContext())
} }
/**
* If enabled, determine the orientation o use based on the video's aspect ratio
* Expected behavior: Portrait for shorts, Landscape for normal videos
*/
private fun updateFullscreenOrientation() {
if (!PlayerHelper.autoRotationEnabled) {
val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height
val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width
// different orientations of the video are only available when autorotation is disabled
val orientation = PlayerHelper.getOrientation(width, height)
mainActivity.requestedOrientation = orientation
}
}
private fun setFullscreen() { private fun setFullscreen() {
with(binding.playerMotionLayout) { with(binding.playerMotionLayout) {
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1) getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
@ -525,14 +540,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
playerBinding.exoTitle.visibility = View.VISIBLE playerBinding.exoTitle.visibility = View.VISIBLE
if (!PlayerHelper.autoRotationEnabled) { updateFullscreenOrientation()
val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height
val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width
// different orientations of the video are only available when autorotation is disabled
val orientation = PlayerHelper.getOrientation(width, height)
mainActivity.requestedOrientation = orientation
}
viewModel.isFullscreen.value = true viewModel.isFullscreen.value = true
} }
@ -746,6 +754,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
prepareExoPlayerView() prepareExoPlayerView()
initializePlayerView() initializePlayerView()
setupSeekbarPreview() setupSeekbarPreview()
updateFullscreenOrientation()
exoPlayer.prepare() exoPlayer.prepare()
if (PreferenceHelper.getBoolean(PreferenceKeys.PLAY_AUTOMATICALLY, true)) { if (PreferenceHelper.getBoolean(PreferenceKeys.PLAY_AUTOMATICALLY, true)) {