Add setting "Rotate to portrait when exiting fullscreen"

This commit is contained in:
Arkadiusz Fal 2022-08-07 13:48:50 +02:00
parent 8e2c30bf00
commit 0365369dcd
7 changed files with 31 additions and 46 deletions

View File

@ -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

View File

@ -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() {

View File

@ -45,9 +45,6 @@ protocol PlayerBackend {
func closeItem()
func enterFullScreen()
func exitFullScreen()
func closePiP(wasPlaying: Bool)
func updateControls()

View File

@ -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
}

View File

@ -94,6 +94,7 @@ extension Defaults.Keys {
#if os(iOS)
static let honorSystemOrientationLock = Key<Bool>("honorSystemOrientationLock", default: true)
static let enterFullscreenInLandscape = Key<Bool>("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone)
static let rotateToPortraitOnExitFullScreen = Key<Bool>("rotateToPortraitOnExitFullScreen", default: UIDevice.current.userInterfaceIdiom == .phone)
#endif
static let showMPVPlaybackStats = Key<Bool>("showMPVPlaybackStats", default: false)

View File

@ -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)
}
}

View File

@ -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 {