mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
respect orientation pref for downloaded videos
This commit is contained in:
parent
512844805a
commit
5df5a2a9c5
@ -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() {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user