mirror of
https://github.com/yattee/yattee.git
synced 2024-12-12 21:30:32 +05:30
apply new fullscreen logic to AppleAVPlayerView
Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
parent
4e4add3c42
commit
b2421da95d
@ -136,8 +136,9 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen
|
@Default(.rotateToLandscapeOnEnterFullScreen) var rotateToLandscapeOnEnterFullScreen
|
||||||
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
|
@Default(.lockPortraitWhenBrowsing) var lockPortraitWhenBrowsing
|
||||||
|
var fullscreenInitiatedByButton = false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@Published var currentChapterIndex: Int?
|
@Published var currentChapterIndex: Int?
|
||||||
@ -1150,6 +1151,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
if playingFullScreen {
|
if playingFullScreen {
|
||||||
if activeBackend == .appleAVPlayer, avPlayerUsesSystemControls {
|
if activeBackend == .appleAVPlayer, avPlayerUsesSystemControls {
|
||||||
|
fullscreenInitiatedByButton = initiatedByButton
|
||||||
avPlayerBackend.controller.enterFullScreen(animated: true)
|
avPlayerBackend.controller.enterFullScreen(animated: true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1177,7 +1179,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
avPlayerBackend.controller.dismiss(animated: true)
|
avPlayerBackend.controller.dismiss(animated: true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if Defaults[.lockPortraitWhenBrowsing] {
|
if lockPortraitWhenBrowsing {
|
||||||
lockedOrientation = UIInterfaceOrientationMask.portrait
|
lockedOrientation = UIInterfaceOrientationMask.portrait
|
||||||
}
|
}
|
||||||
let rotationOrientation = lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil
|
let rotationOrientation = lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil
|
||||||
|
@ -4,11 +4,6 @@ import SwiftUI
|
|||||||
|
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
final class AppleAVPlayerViewControllerDelegate: NSObject, AVPlayerViewControllerDelegate {
|
final class AppleAVPlayerViewControllerDelegate: NSObject, AVPlayerViewControllerDelegate {
|
||||||
#if os(iOS)
|
|
||||||
@Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen
|
|
||||||
@Default(.avPlayerUsesSystemControls) private var avPlayerUsesSystemControls
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var player: PlayerModel { .shared }
|
var player: PlayerModel { .shared }
|
||||||
|
|
||||||
func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_: AVPlayerViewController) -> Bool {
|
func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_: AVPlayerViewController) -> Bool {
|
||||||
@ -17,14 +12,23 @@ import SwiftUI
|
|||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
func playerViewController(_: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator) {
|
func playerViewController(_: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator) {
|
||||||
if PlayerModel.shared.currentVideoIsLandscape {
|
let lockOrientation = player.rotateToLandscapeOnEnterFullScreen.interfaceOrientation
|
||||||
let delay = PlayerModel.shared.activeBackend == .appleAVPlayer && avPlayerUsesSystemControls ? 0.8 : 0
|
if player.currentVideoIsLandscape {
|
||||||
// not sure why but first rotation call is ignore so doing rotate to same orientation first
|
if player.fullscreenInitiatedByButton {
|
||||||
Delay.by(delay) {
|
Orientation.lockOrientation(player.isOrientationLocked
|
||||||
let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape ? OrientationTracker.shared.currentInterfaceOrientation : self.rotateToLandscapeOnEnterFullScreen.interfaceOrientation
|
? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft)
|
||||||
Orientation.lockOrientation(.all, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation)
|
: .landscape)
|
||||||
Orientation.lockOrientation(.all, andRotateTo: orientation)
|
|
||||||
}
|
}
|
||||||
|
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 !context.isCancelled {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
if Constants.isIPhone {
|
if self.player.lockPortraitWhenBrowsing {
|
||||||
Orientation.lockOrientation(.all, andRotateTo: .portrait)
|
self.player.lockedOrientation = UIInterfaceOrientationMask.portrait
|
||||||
}
|
}
|
||||||
|
let rotationOrientation = self.player.lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil
|
||||||
|
Orientation.lockOrientation(self.player.lockPortraitWhenBrowsing ? .portrait : .all, andRotateTo: rotationOrientation)
|
||||||
|
|
||||||
if wasPlaying {
|
if wasPlaying {
|
||||||
self.player.play()
|
self.player.play()
|
||||||
|
Loading…
Reference in New Issue
Block a user