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

45 lines
1.3 KiB
Swift
Raw 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
let orientation = UIApplication.shared.statusBarOrientation
return orientation
}
}
#endif
}