diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index f00ab36a..f4b7f3a6 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -136,8 +136,9 @@ final class PlayerModel: ObservableObject { } } - @Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen - @Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing + @Default(.rotateToLandscapeOnEnterFullScreen) var rotateToLandscapeOnEnterFullScreen + @Default(.lockPortraitWhenBrowsing) var lockPortraitWhenBrowsing + var fullscreenInitiatedByButton = false #endif @Published var currentChapterIndex: Int? @@ -1150,6 +1151,7 @@ final class PlayerModel: ObservableObject { #if os(iOS) if playingFullScreen { if activeBackend == .appleAVPlayer, avPlayerUsesSystemControls { + fullscreenInitiatedByButton = initiatedByButton avPlayerBackend.controller.enterFullScreen(animated: true) return } @@ -1177,7 +1179,7 @@ final class PlayerModel: ObservableObject { avPlayerBackend.controller.dismiss(animated: true) return } - if Defaults[.lockPortraitWhenBrowsing] { + if lockPortraitWhenBrowsing { lockedOrientation = UIInterfaceOrientationMask.portrait } let rotationOrientation = lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil diff --git a/Shared/Player/AppleAVPlayerView.swift b/Shared/Player/AppleAVPlayerView.swift index 98d784fa..ac5d524d 100644 --- a/Shared/Player/AppleAVPlayerView.swift +++ b/Shared/Player/AppleAVPlayerView.swift @@ -4,11 +4,6 @@ import SwiftUI #if !os(macOS) final class AppleAVPlayerViewControllerDelegate: NSObject, AVPlayerViewControllerDelegate { - #if os(iOS) - @Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen - @Default(.avPlayerUsesSystemControls) private var avPlayerUsesSystemControls - #endif - var player: PlayerModel { .shared } func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_: AVPlayerViewController) -> Bool { @@ -17,14 +12,23 @@ import SwiftUI #if os(iOS) func playerViewController(_: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator) { - if PlayerModel.shared.currentVideoIsLandscape { - let delay = PlayerModel.shared.activeBackend == .appleAVPlayer && avPlayerUsesSystemControls ? 0.8 : 0 - // not sure why but first rotation call is ignore so doing rotate to same orientation first - Delay.by(delay) { - let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape ? OrientationTracker.shared.currentInterfaceOrientation : self.rotateToLandscapeOnEnterFullScreen.interfaceOrientation - Orientation.lockOrientation(.all, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation) - Orientation.lockOrientation(.all, andRotateTo: orientation) + let lockOrientation = player.rotateToLandscapeOnEnterFullScreen.interfaceOrientation + if player.currentVideoIsLandscape { + if player.fullscreenInitiatedByButton { + Orientation.lockOrientation(player.isOrientationLocked + ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) + : .landscape) } + let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape + ? OrientationTracker.shared.currentInterfaceOrientation + : player.rotateToLandscapeOnEnterFullScreen.interfaceOrientation + + Orientation.lockOrientation( + player.isOrientationLocked + ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) + : .all, + andRotateTo: orientation + ) } } @@ -36,9 +40,11 @@ import SwiftUI } if !context.isCancelled { #if os(iOS) - if Constants.isIPhone { - Orientation.lockOrientation(.all, andRotateTo: .portrait) + if self.player.lockPortraitWhenBrowsing { + self.player.lockedOrientation = UIInterfaceOrientationMask.portrait } + let rotationOrientation = self.player.lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil + Orientation.lockOrientation(self.player.lockPortraitWhenBrowsing ? .portrait : .all, andRotateTo: rotationOrientation) if wasPlaying { self.player.play()