diff --git a/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt index 97f82433c..c199f1998 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt @@ -18,6 +18,7 @@ import com.github.libretube.databinding.ActivityOfflinePlayerBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.ui.base.BaseActivity import com.github.libretube.util.DownloadHelper +import com.github.libretube.util.PlayerHelper import com.github.libretube.util.PreferenceHelper import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.MediaItem @@ -48,6 +49,8 @@ class OfflinePlayerActivity : BaseActivity() { initializePlayer() playVideo() + + requestedOrientation = PlayerHelper.getOrientation(player.videoSize) } private fun initializePlayer() { 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 d6a82c925..504d9da45 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 @@ -154,7 +154,6 @@ class PlayerFragment : BaseFragment() { private var relatedStreamsEnabled = true private var autoRotationEnabled = true private var pausePlayerOnScreenOffEnabled = false - private var fullscreenOrientationPref = "ratio" private var watchHistoryEnabled = true private var watchPositionsEnabled = true private var useSystemCaptionStyle = true @@ -256,11 +255,6 @@ class PlayerFragment : BaseFragment() { true ) - fullscreenOrientationPref = PreferenceHelper.getString( - PreferenceKeys.FULLSCREEN_ORIENTATION, - "ratio" - ) - pausePlayerOnScreenOffEnabled = PreferenceHelper.getBoolean( PreferenceKeys.PAUSE_ON_SCREEN_OFF, false @@ -584,22 +578,7 @@ class PlayerFragment : BaseFragment() { val mainActivity = activity as MainActivity if (!autoRotationEnabled) { // different orientations of the video are only available when auto rotation is disabled - val orientation = when (fullscreenOrientationPref) { - "ratio" -> { - val videoSize = exoPlayer.videoSize - // probably a youtube shorts video - if (videoSize.height > videoSize.width) { - ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - } // a video with normal aspect ratio - else { - ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE - } - } - "auto" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR - "landscape" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE - "portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - else -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE - } + val orientation = PlayerHelper.getOrientation(exoPlayer.videoSize) mainActivity.requestedOrientation = orientation } diff --git a/app/src/main/java/com/github/libretube/util/PlayerHelper.kt b/app/src/main/java/com/github/libretube/util/PlayerHelper.kt index fc1396464..24f62b86b 100644 --- a/app/src/main/java/com/github/libretube/util/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/util/PlayerHelper.kt @@ -1,9 +1,11 @@ package com.github.libretube.util import android.content.Context +import android.content.pm.ActivityInfo import android.view.accessibility.CaptioningManager import com.github.libretube.constants.PreferenceKeys import com.google.android.exoplayer2.ui.CaptionStyleCompat +import com.google.android.exoplayer2.video.VideoSize object PlayerHelper { // get the audio source following the users preferences @@ -137,4 +139,27 @@ object PlayerHelper { } return categories } + + fun getOrientation(videoSize: VideoSize): Int { + val fullscreenOrientationPref = PreferenceHelper.getString( + PreferenceKeys.FULLSCREEN_ORIENTATION, + "ratio" + ) + + return when (fullscreenOrientationPref) { + "ratio" -> { + // probably a youtube shorts video + if (videoSize.height > videoSize.width) { + ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } // a video with normal aspect ratio + else { + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + } + } + "auto" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR + "landscape" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + "portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + else -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + } + } }