更改了一种图片投屏的方式

This commit is contained in:
bluesea 2024-03-19 16:00:55 +08:00
parent 079c4693cc
commit 6bd53acba3
2 changed files with 32 additions and 17 deletions

View File

@ -166,7 +166,7 @@ class CCHomeController: BaseController, LLCycleScrollViewDelegate,MFMailComposeV
}
private func checkAirPlayStatus() {
print("设备连接变化")
print("设备连接变化 homecontroller")
let currentRoute = AVAudioSession.sharedInstance().currentRoute
let isAirPlayActive = currentRoute.outputs.contains { output in
return output.portType == AVAudioSession.Port.HDMI ||

View File

@ -150,14 +150,18 @@ class CCSpatialPhotoDisplayController: BaseController {
deinit {
print("spatioal photo display 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)
// 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)
// AirPlay
NotificationCenter.default.addObserver(self, selector: #selector(airPlayStatusDidChange(notification:)), name: AVAudioSession.routeChangeNotification, object: nil)
self.view.backgroundColor = UIColor(hexString: "#060507")
outputVideoURL = URL.documentsDirectory.appending(path:"output11114.jpg")
@ -207,21 +211,18 @@ class CCSpatialPhotoDisplayController: BaseController {
}
//MARK: -
@objc func exScreenWillConnectNotification(notification:Notification) {
checkAirPlayStatus()
print("外连接。。。。。")
}
@objc func exScreenDisConnectNotification(notification:Notification) {
print("已断开 屏幕。。。。。")
@objc func airPlayStatusDidChange(notification:Notification) {
checkAirPlayStatus()
}
// @objc func exScreenDisConnectNotification(notification:Notification) {
// print(" ")
//
// checkAirPlayStatus()
// }
private func checkAirPlayStatus() {
print("设备连接变化")
print("设备连接变化 photodisplaycontroller>>>>>")
let currentRoute = AVAudioSession.sharedInstance().currentRoute
self.isAirPlayActive = currentRoute.outputs.contains { output in
return output.portType == AVAudioSession.Port.HDMI ||
@ -232,20 +233,34 @@ class CCSpatialPhotoDisplayController: BaseController {
func setttinisScreenMirroring(isScreenMirroring:Bool){
//
if(isScreenMirroring){
if let screen = UIScreen.screens.last {
self.externalWindow.screen = screen
print("变化为已连接。。。。")
//
let sessions:Set<UISceneSession> = UIApplication.shared.openSessions
//
let otherScreenSessions:Set<UISceneSession> = sessions.filter {
$0.role.rawValue.contains("External")
}
if let session = otherScreenSessions.first,
let scene = session.scene {
self.externalWindow.windowScene = scene as! UIWindowScene
let nvc = UIViewController()
self.externalWindow.rootViewController = nvc
var imageView = UIImageView(frame: CGRectMake(500, 0, KScreenHeight, KScreenHeight))
var imageView = UIImageView(frame: CGRectMake(0, 0, KScreenHeight*2, KScreenHeight*2))
imageView.contentMode = .scaleAspectFit
externalImageView = imageView
nvc.view.addSubview(imageView)
self.externalWindow.isHidden = false
var dispalylink:CADisplayLink? = screen.displayLink(withTarget: self, selector: #selector(displayUpdate(caDisplayLink:)))
var dispalylink:CADisplayLink? = self.externalWindow.windowScene?.windows.first?.screen.displayLink(withTarget: self, selector: #selector(displayUpdate(caDisplayLink:)))
dispalylink?.add(to: RunLoop.main, forMode: RunLoop.Mode.common)
}
else {
print("未发现外接屏....")
}
}
else{
print("变化为 断开。。。。")
if let imv = externalImageView{
imv .removeFromSuperview()
}