react-native-video/ios/Video/RCTVideoPlayerViewController.swift

50 lines
1.5 KiB
Swift
Raw Permalink Normal View History

import AVKit
class RCTVideoPlayerViewController: AVPlayerViewController {
weak var rctDelegate: RCTVideoPlayerViewControllerDelegate?
2023-08-12 04:18:47 -06:00
// Optional paramters
var preferredOrientation: String?
var autorotate: Bool?
2023-08-12 04:18:47 -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
rctDelegate?.videoPlayerViewControllerWillDismiss(playerViewController: self)
rctDelegate?.videoPlayerViewControllerDidDismiss(playerViewController: self)
}
2023-08-12 04:18:47 -06:00
#if !os(tvOS)
func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .all
}
func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
if preferredOrientation?.lowercased() == "landscape" {
return .landscapeRight
} else if preferredOrientation?.lowercased() == "portrait" {
return .portrait
} else {
// default case
if #available(iOS 13, tvOS 13, *) {
return RCTVideoUtils.getCurrentWindow()?.windowScene?.interfaceOrientation ?? .unknown
} else {
#if !os(visionOS)
return UIApplication.shared.statusBarOrientation
#endif
}
}
}
#endif
}