From 5a8375462e6d6c86a2b28b422c3421df37951423 Mon Sep 17 00:00:00 2001 From: Diogo Simao Marques <dogo@videolabs.io> Date: Wed, 22 Jan 2025 08:45:12 +0100 Subject: [PATCH] SettingsSection: Add a setting to force the rotation lock This setting enables the user to automatically enable the rotation lock option when the video player is displayed. The orientation that will be locked is the one selected by the device when the video player is displayed for the first time. It remains the same until the option is disabled or the video player is killed. Closes #1869 --- .../iOS/Settings.bundle/en.lproj/Root.strings | 1 + Sources/Headers/VLCConstants.h | 1 + .../VideoPlayerViewController.swift | 8 ++++++++ Sources/Settings/Model/SettingsSection.swift | 17 +++++++++++------ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Resources/iOS/Settings.bundle/en.lproj/Root.strings b/Resources/iOS/Settings.bundle/en.lproj/Root.strings index 0efdae452..5f42393f2 100644 --- a/Resources/iOS/Settings.bundle/en.lproj/Root.strings +++ b/Resources/iOS/Settings.bundle/en.lproj/Root.strings @@ -97,6 +97,7 @@ "SETTINGS_HWDECODING_INFO" = "Content encoded in the H.264 and H.265 formats can be decoded in hardware leading to a significant improvement of battery life and performance. Be careful when disabling this option."; "SETTINGS_HWDECODING_ON" = "On"; "SETTINGS_HWDECODING_OFF" = "Off"; +"SETTINGS_LOCK_ROTATION" = "Force the rotation lock"; "SETTINGS_CASTING" = "Casting"; "SETTINGS_PTCASTING" = "Audio passthrough"; "SETTINGS_PTCASTINGLONG" = "Let your TV manage audio rendering"; diff --git a/Sources/Headers/VLCConstants.h b/Sources/Headers/VLCConstants.h index 23904a6b3..f77fb4456 100644 --- a/Sources/Headers/VLCConstants.h +++ b/Sources/Headers/VLCConstants.h @@ -49,6 +49,7 @@ #define kVLCSettingDeinterlaceDefaultValue @(-1) #define kVLCSettingHardwareDecoding @"codec" #define kVLCSettingHardwareDecodingDefault @"" +#define kVLCSettingRotationLock @"kVLCSettingRotationLock" #define kVLCSettingNetworkCaching @"network-caching" #define kVLCSettingNetworkCachingDefaultValue @(999) #define kVLCSettingNetworkRTSPTCP @"rtsp-tcp" diff --git a/Sources/Playback/Player/VideoPlayer-iOS/VideoPlayerViewController.swift b/Sources/Playback/Player/VideoPlayer-iOS/VideoPlayerViewController.swift index 25e428b44..3f1af126b 100644 --- a/Sources/Playback/Player/VideoPlayer-iOS/VideoPlayerViewController.swift +++ b/Sources/Playback/Player/VideoPlayer-iOS/VideoPlayerViewController.swift @@ -1316,6 +1316,14 @@ extension VideoPlayerViewController { if currentState == .opening { updateAudioInterface(with: playbackService.metadata) + if UserDefaults.standard.bool(forKey: kVLCSettingRotationLock) { + videoPlayerControls.handleRotationLockButton(videoPlayerControls) + } + } + + if currentState == .stopped { + supportedInterfaceOrientations = .allButUpsideDown + videoPlayerControls.rotationLockButton.tintColor = .white } } diff --git a/Sources/Settings/Model/SettingsSection.swift b/Sources/Settings/Model/SettingsSection.swift index b980173f2..0331bffe5 100644 --- a/Sources/Settings/Model/SettingsSection.swift +++ b/Sources/Settings/Model/SettingsSection.swift @@ -532,13 +532,18 @@ enum VideoOptions { ) } + static var lockRotation: SettingsItem { + .toggle(title: "SETTINGS_LOCK_ROTATION", subtitle: nil, preferenceKey: kVLCSettingRotationLock) + } + static func section() -> SettingsSection? { - .init(title: "SETTINGS_VIDEO_TITLE", items: [ - deBlockingFilter, - deInterlace, - hardwareDecoding, - rememberPlayerBrightness - ]) + var options = [deBlockingFilter, deInterlace, hardwareDecoding, rememberPlayerBrightness] + + if UIDevice.current.userInterfaceIdiom == .phone { + options.append(lockRotation) + } + + return .init(title: "SETTINGS_VIDEO_TITLE", items: options) } } -- GitLab