diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index c166de34..1570d256 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -156,12 +156,6 @@ final class AVPlayerBackend: PlayerBackend { avPlayer.replaceCurrentItem(with: nil) } - func enterFullScreen() { - model.toggleFullscreen(model?.playingFullScreen ?? false) - } - - func exitFullScreen() {} - #if os(tvOS) func closePiP(wasPlaying: Bool) { let item = avPlayer.currentItem diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 38279725..e9411fa4 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -318,12 +318,6 @@ final class MPVBackend: PlayerBackend { client?.stop() } - func enterFullScreen() { - model.toggleFullscreen(model?.playingFullScreen ?? false) - } - - func exitFullScreen() {} - func closePiP(wasPlaying _: Bool) {} func updateControls() { diff --git a/Model/Player/Backends/PlayerBackend.swift b/Model/Player/Backends/PlayerBackend.swift index ee7d1b1b..37747b9d 100644 --- a/Model/Player/Backends/PlayerBackend.swift +++ b/Model/Player/Backends/PlayerBackend.swift @@ -45,9 +45,6 @@ protocol PlayerBackend { func closeItem() - func enterFullScreen() - func exitFullScreen() - func closePiP(wasPlaying: Bool) func updateControls() diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index d65a70a8..9b965a3a 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -95,6 +95,7 @@ final class PlayerModel: ObservableObject { #if os(iOS) @Published var lockedOrientation: UIInterfaceOrientationMask? + @Default(.rotateToPortraitOnExitFullScreen) private var rotateToPortraitOnExitFullScreen #endif var accounts: AccountsModel @@ -103,6 +104,7 @@ final class PlayerModel: ObservableObject { backends.forEach { backend in var backend = backend backend.controls = controls + backend.controls.player = self } }} var playerTime: PlayerTimeModel { didSet { @@ -741,28 +743,18 @@ final class PlayerModel: ObservableObject { } } - func enterFullScreen() { - guard !playingFullScreen else { - return - } + func enterFullScreen(showControls: Bool = true) { + guard !playingFullScreen else { return } logger.info("entering fullscreen") - - backend.enterFullScreen() + toggleFullscreen(false, showControls: showControls) } - func exitFullScreen() { - guard playingFullScreen else { - return - } + func exitFullScreen(showControls: Bool = true) { + guard playingFullScreen else { return } logger.info("exiting fullscreen") - - if playingFullScreen { - toggleFullscreen(true) - } - - backend.exitFullScreen() + toggleFullscreen(true, showControls: showControls) } #endif @@ -822,8 +814,8 @@ final class PlayerModel: ObservableObject { task.resume() } - func toggleFullscreen(_ isFullScreen: Bool) { - controls.presentingControls = false + func toggleFullscreen(_ isFullScreen: Bool, showControls: Bool = true) { + controls.presentingControls = showControls && isFullScreen #if os(macOS) if isFullScreen { @@ -848,7 +840,8 @@ final class PlayerModel: ObservableObject { #if os(iOS) if !playingFullScreen { - Orientation.lockOrientation(.allButUpsideDown) + let rotationOrientation = rotateToPortraitOnExitFullScreen ? UIInterfaceOrientation.portrait : nil + Orientation.lockOrientation(.allButUpsideDown, andRotateTo: rotationOrientation) } #endif } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 9bcb6601..7ac194b4 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -94,6 +94,7 @@ extension Defaults.Keys { #if os(iOS) static let honorSystemOrientationLock = Key("honorSystemOrientationLock", default: true) static let enterFullscreenInLandscape = Key("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone) + static let rotateToPortraitOnExitFullScreen = Key("rotateToPortraitOnExitFullScreen", default: UIDevice.current.userInterfaceIdiom == .phone) #endif static let showMPVPlaybackStats = Key("showMPVPlaybackStats", default: false) diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index eaa23708..5693ee7d 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -415,7 +415,7 @@ struct VideoPlayerView: View { { DispatchQueue.main.async { player.controls.presentingControls = false - player.enterFullScreen() + player.enterFullScreen(showControls: false) } } @@ -447,10 +447,10 @@ struct VideoPlayerView: View { if orientation.isLandscape { player.controls.presentingControls = false - player.enterFullScreen() + player.enterFullScreen(showControls: false) Orientation.lockOrientation(OrientationTracker.shared.currentInterfaceOrientationMask, andRotateTo: orientation) } else { - player.exitFullScreen() + player.exitFullScreen(showControls: false) Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait) } } diff --git a/Shared/Settings/PlayerSettings.swift b/Shared/Settings/PlayerSettings.swift index 0ff0ab6d..8533021b 100644 --- a/Shared/Settings/PlayerSettings.swift +++ b/Shared/Settings/PlayerSettings.swift @@ -14,6 +14,7 @@ struct PlayerSettings: View { #if os(iOS) @Default(.honorSystemOrientationLock) private var honorSystemOrientationLock @Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape + @Default(.rotateToPortraitOnExitFullScreen) private var rotateToPortraitOnExitFullScreen #endif @Default(.closePiPOnNavigation) private var closePiPOnNavigation @Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer @@ -84,6 +85,16 @@ struct PlayerSettings: View { returnYouTubeDislikeToggle } + #if os(iOS) + Section(header: SettingsHeader(text: "Orientation")) { + if idiom == .pad { + enterFullscreenInLandscapeToggle + } + rotateToPortraitOnExitFullScreenToggle + honorSystemOrientationLockToggle + } + #endif + Section(header: SettingsHeader(text: "Picture in Picture")) { closePiPOnNavigationToggle closePiPOnOpeningPlayerToggle @@ -91,15 +102,6 @@ struct PlayerSettings: View { closePiPAndOpenPlayerOnEnteringForegroundToggle #endif } - - #if os(iOS) - Section(header: SettingsHeader(text: "Orientation")) { - if idiom == .pad { - enterFullscreenInLandscapeToggle - } - honorSystemOrientationLockToggle - } - #endif } } @@ -196,6 +198,10 @@ struct PlayerSettings: View { private var enterFullscreenInLandscapeToggle: some View { Toggle("Enter fullscreen in landscape", isOn: $enterFullscreenInLandscape) } + + private var rotateToPortraitOnExitFullScreenToggle: some View { + Toggle("Rotate to portrait when exiting fullscreen", isOn: $rotateToPortraitOnExitFullScreen) + } #endif private var closePiPOnNavigationToggle: some View {