From c49eef5faf1ad0df2f972e4b2974eed75bc35293 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 29 Oct 2023 18:54:50 +0100 Subject: [PATCH] fix: crash on startup when auto fullscreen enabled --- .../libretube/ui/fragments/PlayerFragment.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 05743bb11..8aad90ac5 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -519,18 +519,22 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { NavigationHelper.startAudioPlayer(requireContext()) } + private fun updateFullscreenOrientation() { + if (PlayerHelper.autoFullscreenEnabled || this::streams.isInitialized) return + + val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height + val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width + + mainActivity.requestedOrientation = PlayerHelper.getOrientation(width, height) + } + private fun setFullscreen() { // set status bar icon color to white windowInsetsControllerCompat.isAppearanceLightStatusBars = false viewModel.isFullscreen.value = true - if (mainActivity.screenOrientationPref == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT) { - val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height - val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width - - mainActivity.requestedOrientation = PlayerHelper.getOrientation(width, height) - } + updateFullscreenOrientation() commentsViewModel.setCommentSheetExpand(null) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit) @@ -1348,7 +1352,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { if (PlayerHelper.autoFullscreenEnabled) { // enable auto rotation mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR - onConfigurationChanged(resources.configuration) } else { // go to portrait mode mainActivity.requestedOrientation = (requireActivity() as BaseActivity).screenOrientationPref