Skip to content

Commit

Permalink
Don't automatically change orientation for landscape video (#809)
Browse files Browse the repository at this point in the history
Instead, make it configurable through a preference, which is turned off by default.

Co-authored-by: Maxr1998 <max.rumpf1998@gmail.com>
  • Loading branch information
eglia and Maxr1998 authored Nov 26, 2022
1 parent 666a95a commit b8db53f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/org/jellyfin/mobile/app/AppPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class AppPreferences(context: Context) {
val videoPlayerType: String
get() = sharedPreferences.getString(Constants.PREF_VIDEO_PLAYER_TYPE, VideoPlayerType.WEB_PLAYER)!!

val exoPlayerStartLandscapeVideoInLandscape: Boolean
get() = sharedPreferences.getBoolean(Constants.PREF_EXOPLAYER_START_LANDSCAPE_VIDEO_IN_LANDSCAPE, false)

val exoPlayerAllowSwipeGestures: Boolean
get() = sharedPreferences.getBoolean(Constants.PREF_EXOPLAYER_ALLOW_SWIPE_GESTURES, true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerView
import kotlinx.coroutines.launch
import org.jellyfin.mobile.R
import org.jellyfin.mobile.app.AppPreferences
import org.jellyfin.mobile.databinding.ExoPlayerControlViewBinding
import org.jellyfin.mobile.databinding.FragmentPlayerBinding
import org.jellyfin.mobile.player.PlayerException
Expand All @@ -46,8 +47,10 @@ import org.jellyfin.mobile.utils.extensions.isFullscreen
import org.jellyfin.mobile.utils.extensions.isLandscape
import org.jellyfin.mobile.utils.toast
import org.jellyfin.sdk.model.api.MediaStream
import org.koin.android.ext.android.inject

class PlayerFragment : Fragment() {
private val appPreferences: AppPreferences by inject()
private val viewModel: PlayerViewModel by viewModels()
private var _playerBinding: FragmentPlayerBinding? = null
private val playerBinding: FragmentPlayerBinding get() = _playerBinding!!
Expand Down Expand Up @@ -99,13 +102,13 @@ class PlayerFragment : Fragment() {
val jellyfinMediaSource = queueItem.jellyfinMediaSource

with(requireActivity()) {
if (jellyfinMediaSource.selectedVideoStream?.isLandscape != false) {
// Switch to landscape for landscape videos
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
} else {
if (jellyfinMediaSource.selectedVideoStream?.isLandscape == false) {
// For portrait videos, immediately enable fullscreen
enableFullscreen()
updateFullscreenSwitcher(isFullscreen())
} else if (appPreferences.exoPlayerStartLandscapeVideoInLandscape) {
// Auto-switch to landscape for landscape videos if enabled
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SettingsFragment : Fragment() {

private val appPreferences: AppPreferences by inject()
private val settingsAdapter: PreferencesAdapter by lazy { PreferencesAdapter(buildSettingsScreen()) }
private lateinit var startLandscapeVideoInLandscapePreference: CheckBoxPreference
private lateinit var swipeGesturesPreference: CheckBoxPreference
private lateinit var rememberBrightnessPreference: Preference
private lateinit var backgroundAudioPreference: Preference
Expand Down Expand Up @@ -90,13 +91,18 @@ class SettingsFragment : Fragment() {
titleRes = R.string.pref_video_player_type_title
initialSelection = VideoPlayerType.WEB_PLAYER
defaultOnSelectionChange { selection ->
startLandscapeVideoInLandscapePreference.enabled = selection == VideoPlayerType.EXO_PLAYER
swipeGesturesPreference.enabled = selection == VideoPlayerType.EXO_PLAYER
rememberBrightnessPreference.enabled = selection == VideoPlayerType.EXO_PLAYER && swipeGesturesPreference.checked
backgroundAudioPreference.enabled = selection == VideoPlayerType.EXO_PLAYER
directPlayAssPreference.enabled = selection == VideoPlayerType.EXO_PLAYER
externalPlayerChoicePreference.enabled = selection == VideoPlayerType.EXTERNAL_PLAYER
}
}
startLandscapeVideoInLandscapePreference = checkBox(Constants.PREF_EXOPLAYER_START_LANDSCAPE_VIDEO_IN_LANDSCAPE) {
titleRes = R.string.pref_exoplayer_start_landscape_video_in_landscape
enabled = appPreferences.videoPlayerType == VideoPlayerType.EXO_PLAYER
}
swipeGesturesPreference = checkBox(Constants.PREF_EXOPLAYER_ALLOW_SWIPE_GESTURES) {
titleRes = R.string.pref_exoplayer_allow_brightness_volume_gesture
enabled = appPreferences.videoPlayerType == VideoPlayerType.EXO_PLAYER
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/jellyfin/mobile/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object Constants {
const val PREF_DOWNLOAD_METHOD = "pref_download_method"
const val PREF_MUSIC_NOTIFICATION_ALWAYS_DISMISSIBLE = "pref_music_notification_always_dismissible"
const val PREF_VIDEO_PLAYER_TYPE = "pref_video_player_type"
const val PREF_EXOPLAYER_START_LANDSCAPE_VIDEO_IN_LANDSCAPE = "pref_exoplayer_start_landscape_video_in_landscape"
const val PREF_EXOPLAYER_ALLOW_SWIPE_GESTURES = "pref_exoplayer_allow_swipe_gestures"
const val PREF_EXOPLAYER_REMEMBER_BRIGHTNESS = "pref_exoplayer_remember_brightness"
const val PREF_EXOPLAYER_BRIGHTNESS = "pref_exoplayer_brightness"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<string name="video_player_web_description">The default HTML video player from the Web UI</string>
<string name="video_player_native_description">Based on ExoPlayer, supports more video formats and codecs, and is more integrated into the OS</string>
<string name="video_player_external_description">External video playback apps like MX Player and VLC</string>
<string name="pref_exoplayer_start_landscape_video_in_landscape">Start landscape mode videos in landscape orientation</string>
<string name="pref_exoplayer_allow_brightness_volume_gesture">Brightness and volume gestures</string>
<string name="pref_exoplayer_remember_brightness">Remember display brightness</string>
<string name="pref_exoplayer_allow_background_audio">Background audio</string>
Expand Down

0 comments on commit b8db53f

Please sign in to comment.