Fix player delegate methods

This commit is contained in:
Arkadiusz Fal 2021-07-30 00:28:28 +02:00
parent 5b0a3458f3
commit 994903f8a7
2 changed files with 27 additions and 9 deletions

View File

@ -37,11 +37,20 @@ final class PlayerState: ObservableObject {
return 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 InvidiousAPI.shared.video(video!.id).load().onSuccess { response in
if let video: Video = response.typedContent() { if let video: Video = response.typedContent() {
self.video = video onSuccess(video)
self.playVideo(video)
} }
} }
} }
@ -206,7 +215,7 @@ final class PlayerState: ObservableObject {
if let time = savedTime { if let time = savedTime {
logger.info("seeking to \(time.seconds)") logger.info("seeking to \(time.seconds)")
player.seek(to: time) player.seek(to: time, toleranceBefore: CMTime.zero, toleranceAfter: CMTime.zero)
} }
} }

View File

@ -61,21 +61,30 @@ extension PlayerViewController: AVPlayerViewControllerDelegate {
true true
} }
func playerViewControllerWillBeginDismissalTransition(_: AVPlayerViewController) { func playerViewControllerDidEndDismissalTransition(_: AVPlayerViewController) {
playingFullScreen = false
dismiss(animated: false) dismiss(animated: false)
} }
func playerViewController( func playerViewController(
_: AVPlayerViewController, _: AVPlayerViewController,
willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator
) { ) {
playingFullScreen = true coordinator.animate(alongsideTransition: nil) { context in
if !context.isCancelled {
self.playingFullScreen = true
}
}
} }
func playerViewController( func playerViewController(
_: AVPlayerViewController, _: AVPlayerViewController,
willEndFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator
) { ) {
playingFullScreen = false coordinator.animate(alongsideTransition: nil) { context in
if !context.isCancelled {
self.playingFullScreen = false
}
}
} }
} }