完成图片投屏的功能
This commit is contained in:
parent
d6cbb444f0
commit
079c4693cc
@ -22,6 +22,13 @@ enum VideoReaderError : Error {
|
||||
|
||||
class CCSpatialPhotoDisplayController: BaseController {
|
||||
|
||||
//保留外联屏幕
|
||||
lazy var externalWindow:UIWindow = {
|
||||
return UIWindow(frame: self.view.bounds)
|
||||
}()
|
||||
|
||||
var externalImageView:UIImageView?
|
||||
|
||||
var player:AVPlayer = AVPlayer()
|
||||
|
||||
var outputVideoURL:URL?
|
||||
@ -115,10 +122,6 @@ class CCSpatialPhotoDisplayController: BaseController {
|
||||
|
||||
lazy var menuView: CCSpatialDisplayTypeView = {
|
||||
//数据源(icon可不填)
|
||||
// let popData = [(icon:"type_check",title:"单眼2D",isHiden:false),
|
||||
// (icon:"type_check",title:"平行眼",isHiden:false),
|
||||
// (icon:"type_check",title:"红蓝立体",isHiden:false),
|
||||
// (icon:"type_check",title:"交叉眼",isHiden:false)]
|
||||
|
||||
//设置参数
|
||||
let parameters:[CCSpatialDisplayTypeConfigure] = [
|
||||
@ -138,8 +141,23 @@ class CCSpatialPhotoDisplayController: BaseController {
|
||||
return popMenu
|
||||
}()
|
||||
|
||||
var isAirPlayActive:Bool = false {
|
||||
didSet{
|
||||
//更新串流UI
|
||||
setttinisScreenMirroring(isScreenMirroring: isAirPlayActive)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
//添加外接屏幕链接通知
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(exScreenWillConnectNotification(notification:)), name: UIScene.willConnectNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(exScreenDisConnectNotification(notification:)), name: UIScene.didDisconnectNotification, object: nil)
|
||||
|
||||
self.view.backgroundColor = UIColor(hexString: "#060507")
|
||||
outputVideoURL = URL.documentsDirectory.appending(path:"output11114.jpg")
|
||||
@ -162,11 +180,6 @@ class CCSpatialPhotoDisplayController: BaseController {
|
||||
image = image?.getUpImg()
|
||||
mImgView.image = image
|
||||
|
||||
// dvc = UIDocumentViewController()
|
||||
// self.addChild(dvc!)
|
||||
// self.view.addSubview(dvc!.view)
|
||||
// var uidc = UIDocument(fileURL: URL(string: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2024%2F0208%2F17870067j00s8iidm0066d000xc00mzp.jpg&thumbnail=660x2147483647&quality=80&type=jpg")!)
|
||||
// dvc?.document = uidc
|
||||
|
||||
let isSpatial = isSpatialImage(originalData: originalData!)
|
||||
if !isSpatial {
|
||||
@ -188,8 +201,66 @@ class CCSpatialPhotoDisplayController: BaseController {
|
||||
self.view.addSubview(mImgView)
|
||||
|
||||
|
||||
checkAirPlayStatus()
|
||||
|
||||
|
||||
}
|
||||
|
||||
//MARK: - 外接屏幕 链接 与 断开
|
||||
@objc func exScreenWillConnectNotification(notification:Notification) {
|
||||
|
||||
|
||||
checkAirPlayStatus()
|
||||
print("外连接。。。。。")
|
||||
}
|
||||
|
||||
@objc func exScreenDisConnectNotification(notification:Notification) {
|
||||
print("已断开 屏幕。。。。。")
|
||||
|
||||
checkAirPlayStatus()
|
||||
}
|
||||
|
||||
private func checkAirPlayStatus() {
|
||||
print("设备连接变化")
|
||||
let currentRoute = AVAudioSession.sharedInstance().currentRoute
|
||||
self.isAirPlayActive = currentRoute.outputs.contains { output in
|
||||
return output.portType == AVAudioSession.Port.HDMI ||
|
||||
output.portType == AVAudioSession.Port.airPlay
|
||||
}
|
||||
}
|
||||
|
||||
func setttinisScreenMirroring(isScreenMirroring:Bool){
|
||||
//已连接
|
||||
if(isScreenMirroring){
|
||||
if let screen = UIScreen.screens.last {
|
||||
self.externalWindow.screen = screen
|
||||
let nvc = UIViewController()
|
||||
self.externalWindow.rootViewController = nvc
|
||||
var imageView = UIImageView(frame: CGRectMake(500, 0, KScreenHeight, KScreenHeight))
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
externalImageView = imageView
|
||||
nvc.view.addSubview(imageView)
|
||||
self.externalWindow.isHidden = false
|
||||
var dispalylink:CADisplayLink? = screen.displayLink(withTarget: self, selector: #selector(displayUpdate(caDisplayLink:)))
|
||||
dispalylink?.add(to: RunLoop.main, forMode: RunLoop.Mode.common)
|
||||
}
|
||||
}
|
||||
else{
|
||||
if let imv = externalImageView{
|
||||
imv .removeFromSuperview()
|
||||
}
|
||||
externalImageView = nil
|
||||
self.externalWindow.isHidden = true
|
||||
self.externalWindow.rootViewController = nil
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@objc func displayUpdate(caDisplayLink:CADisplayLink) {
|
||||
if externalImageView?.image != mImgView.image {
|
||||
externalImageView?.image = mImgView.image
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -329,9 +400,16 @@ class CCSpatialPhotoDisplayController: BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
if selectedIndex != 0 {
|
||||
SVProgressHUD.showInfo(withStatus: "串流VR眼镜建设中")
|
||||
}
|
||||
// if selectedIndex != 0 {
|
||||
// SVProgressHUD.showInfo(withStatus: "串流VR眼镜建设中")
|
||||
// }
|
||||
// if let imv = externalImageView {
|
||||
// imv.image = mImgView.image
|
||||
// imv.image = mImgView.image
|
||||
// self.externalWindow.layoutIfNeeded()
|
||||
// self.externalWindow.viewController()?.view.setNeedsDisplay()
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
//MARK: - 判断是不是空间照片
|
||||
@ -392,22 +470,8 @@ class CCSpatialPhotoDisplayController: BaseController {
|
||||
return buffer
|
||||
}
|
||||
|
||||
func airPlayScreen(imageData:NSData){
|
||||
// 开始投屏
|
||||
// let airplaySession = UIScreen.main.startAirPlaySession(withCompletionHandler: { (success, error) in
|
||||
// if success {
|
||||
// print("投屏成功")
|
||||
// } else {
|
||||
// print("投屏失败:\(error)")
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// // 将图片发送到 AirPlay 会话
|
||||
// airplaySession.send(imageData, withType: .image)
|
||||
|
||||
|
||||
}
|
||||
|
||||
//将两张图片合成一张图片
|
||||
func joinImages2( leftImage:CIImage, rightImage:CIImage) -> CIImage {
|
||||
let left = UIImage(ciImage: leftImage )
|
||||
|
||||
Loading…
Reference in New Issue
Block a user