From a206918d0fb21d49bf705778798e1fea13862cbf Mon Sep 17 00:00:00 2001 From: Eric Lee Date: Tue, 9 Jan 2024 02:31:50 -0800 Subject: [PATCH 1/4] [QOL][ATV] Supports back button click when in the native player. --- .../Views/VideoPlayer/NativeVideoPlayer.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift index b03f8c93e..24df8093a 100644 --- a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift +++ b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift @@ -3,7 +3,7 @@ // License, v2.0. If a copy of the MPL was not distributed with this // file, you can obtain one at https://mozilla.org/MPL/2.0/. // -// Copyright (c) 2023 Jellyfin & Jellyfin Contributors +// Copyright (c) 2024 Jellyfin & Jellyfin Contributors // import AVKit @@ -37,7 +37,6 @@ struct NativeVideoPlayer: View { if let _ = videoPlayerManager.currentViewModel { playerView } else { -// VideoPlayer.LoadingView() Text("Loading") } } @@ -57,7 +56,9 @@ struct NativeVideoPlayerView: UIViewControllerRepresentable { func updateUIViewController(_ uiViewController: UINativeVideoPlayerViewController, context: Context) {} } -class UINativeVideoPlayerViewController: AVPlayerViewController { +// TODO: Refactor such that this does not subclass AVPlayerViewController. Subclassing is not +// supported according to the apple docs. +class UINativeVideoPlayerViewController: AVPlayerViewController, AVPlayerViewControllerDelegate { let videoPlayerManager: VideoPlayerManager @@ -104,6 +105,7 @@ class UINativeVideoPlayerViewController: AVPlayerViewController { } player = newPlayer + self.delegate = self } @available(*, unavailable) @@ -172,4 +174,11 @@ class UINativeVideoPlayerViewController: AVPlayerViewController { videoPlayerManager.sendStopReport() } + + // MARK: AVPlayerViewControllerDelegateFunctions + + public func playerViewControllerShouldDismiss(_ playerViewController: AVPlayerViewController) -> Bool { + dismiss(animated: true) + return true + } } From cd42e8789005ec23c732f11599eb974fdef09795 Mon Sep 17 00:00:00 2001 From: Eric Lee Date: Sat, 13 Jan 2024 14:59:14 -0800 Subject: [PATCH 2/4] Applies LePips@ comments. --- .../Coordinators/VideoPlayerCoordinator.swift | 20 +++++++++---------- .../Views/VideoPlayer/NativeVideoPlayer.swift | 10 +--------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Shared/Coordinators/VideoPlayerCoordinator.swift b/Shared/Coordinators/VideoPlayerCoordinator.swift index a31f09c90..656c3c858 100644 --- a/Shared/Coordinators/VideoPlayerCoordinator.swift +++ b/Shared/Coordinators/VideoPlayerCoordinator.swift @@ -3,7 +3,7 @@ // License, v2.0. If a copy of the MPL was not distributed with this // file, you can obtain one at https://mozilla.org/MPL/2.0/. // -// Copyright (c) 2023 Jellyfin & Jellyfin Contributors +// Copyright (c) 2024 Jellyfin & Jellyfin Contributors // import Defaults @@ -45,19 +45,17 @@ final class VideoPlayerCoordinator: NavigationCoordinatable { AppDelegate.enterPlaybackOrientation() } - #else - - PreferenceUIHostingControllerView { - Group { - if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin { + #else // os(iOS) + if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin { + PreferenceUIHostingControllerView { + Group { VideoPlayer(manager: self.videoPlayerManager) - } else { - NativeVideoPlayer(manager: self.videoPlayerManager) } } + .ignoresSafeArea() + } else { + NativeVideoPlayer(manager: self.videoPlayerManager) } - .ignoresSafeArea() - - #endif + #endif // os(iOS) } } diff --git a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift index 24df8093a..8cd76ebfb 100644 --- a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift +++ b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift @@ -58,7 +58,7 @@ struct NativeVideoPlayerView: UIViewControllerRepresentable { // TODO: Refactor such that this does not subclass AVPlayerViewController. Subclassing is not // supported according to the apple docs. -class UINativeVideoPlayerViewController: AVPlayerViewController, AVPlayerViewControllerDelegate { +class UINativeVideoPlayerViewController: AVPlayerViewController { let videoPlayerManager: VideoPlayerManager @@ -105,7 +105,6 @@ class UINativeVideoPlayerViewController: AVPlayerViewController, AVPlayerViewCon } player = newPlayer - self.delegate = self } @available(*, unavailable) @@ -174,11 +173,4 @@ class UINativeVideoPlayerViewController: AVPlayerViewController, AVPlayerViewCon videoPlayerManager.sendStopReport() } - - // MARK: AVPlayerViewControllerDelegateFunctions - - public func playerViewControllerShouldDismiss(_ playerViewController: AVPlayerViewController) -> Bool { - dismiss(animated: true) - return true - } } From dbb9c6dbeeaa5b7898a1cc6ce6cadc6f46627f44 Mon Sep 17 00:00:00 2001 From: Eric Lee Date: Sat, 13 Jan 2024 18:08:40 -0800 Subject: [PATCH 3/4] Fixes comments. --- Shared/Coordinators/VideoPlayerCoordinator.swift | 4 ++-- Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Shared/Coordinators/VideoPlayerCoordinator.swift b/Shared/Coordinators/VideoPlayerCoordinator.swift index 656c3c858..939c8ab9b 100644 --- a/Shared/Coordinators/VideoPlayerCoordinator.swift +++ b/Shared/Coordinators/VideoPlayerCoordinator.swift @@ -45,7 +45,7 @@ final class VideoPlayerCoordinator: NavigationCoordinatable { AppDelegate.enterPlaybackOrientation() } - #else // os(iOS) + #else if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin { PreferenceUIHostingControllerView { Group { @@ -56,6 +56,6 @@ final class VideoPlayerCoordinator: NavigationCoordinatable { } else { NativeVideoPlayer(manager: self.videoPlayerManager) } - #endif // os(iOS) + #endif } } diff --git a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift index 8cd76ebfb..222dd0d1f 100644 --- a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift +++ b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift @@ -37,6 +37,7 @@ struct NativeVideoPlayer: View { if let _ = videoPlayerManager.currentViewModel { playerView } else { + // TODO: Implement more polished loading screen. Text("Loading") } } From 9059ac92c9e146c152a62696c994686ac59941f7 Mon Sep 17 00:00:00 2001 From: Eric Lee Date: Mon, 15 Jan 2024 18:13:47 -0800 Subject: [PATCH 4/4] Linter fix. --- Shared/Coordinators/VideoPlayerCoordinator.swift | 6 ++---- Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Shared/Coordinators/VideoPlayerCoordinator.swift b/Shared/Coordinators/VideoPlayerCoordinator.swift index 939c8ab9b..b5dc25076 100644 --- a/Shared/Coordinators/VideoPlayerCoordinator.swift +++ b/Shared/Coordinators/VideoPlayerCoordinator.swift @@ -48,14 +48,12 @@ final class VideoPlayerCoordinator: NavigationCoordinatable { #else if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin { PreferenceUIHostingControllerView { - Group { - VideoPlayer(manager: self.videoPlayerManager) - } + VideoPlayer(manager: self.videoPlayerManager) } .ignoresSafeArea() } else { NativeVideoPlayer(manager: self.videoPlayerManager) } - #endif + #endif } } diff --git a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift index 222dd0d1f..6b6097c86 100644 --- a/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift +++ b/Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift @@ -37,7 +37,7 @@ struct NativeVideoPlayer: View { if let _ = videoPlayerManager.currentViewModel { playerView } else { - // TODO: Implement more polished loading screen. +// VideoPlayer.LoadingView() Text("Loading") } }