diff --git a/Model/PlayerState.swift b/Model/PlayerState.swift index 417f3c5d..b2d2ab02 100644 --- a/Model/PlayerState.swift +++ b/Model/PlayerState.swift @@ -37,11 +37,20 @@ final class PlayerState: ObservableObject { return } + loadExtendedVideoDetails(video) { video in + self.video = video + self.playVideo(video) + } + } + + func loadExtendedVideoDetails(_ video: Video?, onSuccess: @escaping (Video) -> Void) { + guard video != nil else { + return + } + InvidiousAPI.shared.video(video!.id).load().onSuccess { response in if let video: Video = response.typedContent() { - self.video = video - - self.playVideo(video) + onSuccess(video) } } } @@ -206,7 +215,7 @@ final class PlayerState: ObservableObject { if let time = savedTime { logger.info("seeking to \(time.seconds)") - player.seek(to: time) + player.seek(to: time, toleranceBefore: CMTime.zero, toleranceAfter: CMTime.zero) } } diff --git a/Shared/PlayerViewController.swift b/Shared/PlayerViewController.swift index cd2ef1a1..5de8e49b 100644 --- a/Shared/PlayerViewController.swift +++ b/Shared/PlayerViewController.swift @@ -61,21 +61,30 @@ extension PlayerViewController: AVPlayerViewControllerDelegate { true } - func playerViewControllerWillBeginDismissalTransition(_: AVPlayerViewController) { + func playerViewControllerDidEndDismissalTransition(_: AVPlayerViewController) { + playingFullScreen = false dismiss(animated: false) } func playerViewController( _: AVPlayerViewController, - willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator + willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator ) { - playingFullScreen = true + coordinator.animate(alongsideTransition: nil) { context in + if !context.isCancelled { + self.playingFullScreen = true + } + } } func playerViewController( _: AVPlayerViewController, - willEndFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator + willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator ) { - playingFullScreen = false + coordinator.animate(alongsideTransition: nil) { context in + if !context.isCancelled { + self.playingFullScreen = false + } + } } }