2022-05-19 07:29:25 -06:00
|
|
|
import AVKit
|
|
|
|
|
|
|
|
class RCTVideoPlayerViewController: AVPlayerViewController {
|
2023-07-06 01:52:33 -06:00
|
|
|
weak var rctDelegate: RCTVideoPlayerViewControllerDelegate?
|
2023-08-12 04:18:47 -06:00
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
// Optional paramters
|
2023-12-07 00:47:40 -07:00
|
|
|
var preferredOrientation: String?
|
|
|
|
var autorotate: Bool?
|
2023-08-12 04:18:47 -06:00
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
func shouldAutorotate() -> Bool {
|
|
|
|
if autorotate! || preferredOrientation == nil || (preferredOrientation!.lowercased() == "all") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
|
|
super.viewDidDisappear(animated)
|
2023-08-12 04:18:47 -06:00
|
|
|
|
2023-07-06 01:52:33 -06:00
|
|
|
rctDelegate?.videoPlayerViewControllerWillDismiss(playerViewController: self)
|
|
|
|
rctDelegate?.videoPlayerViewControllerDidDismiss(playerViewController: self)
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
|
|
|
|
2023-08-12 04:18:47 -06:00
|
|
|
#if !os(tvOS)
|
2022-05-19 07:29:25 -06:00
|
|
|
|
2023-12-07 00:47:40 -07:00
|
|
|
func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
|
|
|
|
return .all
|
|
|
|
}
|
2022-05-19 07:29:25 -06:00
|
|
|
|
2023-12-07 00:47:40 -07:00
|
|
|
func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
|
|
|
|
if preferredOrientation?.lowercased() == "landscape" {
|
|
|
|
return .landscapeRight
|
|
|
|
} else if preferredOrientation?.lowercased() == "portrait" {
|
|
|
|
return .portrait
|
|
|
|
} else {
|
|
|
|
// default case
|
2023-12-28 04:58:25 -07:00
|
|
|
if #available(iOS 13, tvOS 13, *) {
|
|
|
|
return RCTVideoUtils.getCurrentWindow()?.windowScene?.interfaceOrientation ?? .unknown
|
|
|
|
} else {
|
|
|
|
#if !os(visionOS)
|
|
|
|
return UIApplication.shared.statusBarOrientation
|
|
|
|
#endif
|
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
}
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
#endif
|
|
|
|
}
|