更改了一种图片投屏的方式
This commit is contained in:
parent
079c4693cc
commit
6bd53acba3
@ -166,7 +166,7 @@ class CCHomeController: BaseController, LLCycleScrollViewDelegate,MFMailComposeV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func checkAirPlayStatus() {
|
private func checkAirPlayStatus() {
|
||||||
print("设备连接变化")
|
print("设备连接变化 homecontroller")
|
||||||
let currentRoute = AVAudioSession.sharedInstance().currentRoute
|
let currentRoute = AVAudioSession.sharedInstance().currentRoute
|
||||||
let isAirPlayActive = currentRoute.outputs.contains { output in
|
let isAirPlayActive = currentRoute.outputs.contains { output in
|
||||||
return output.portType == AVAudioSession.Port.HDMI ||
|
return output.portType == AVAudioSession.Port.HDMI ||
|
||||||
|
|||||||
@ -150,14 +150,18 @@ class CCSpatialPhotoDisplayController: BaseController {
|
|||||||
|
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
print("spatioal photo display deinit...")
|
||||||
NotificationCenter.default.removeObserver(self)
|
NotificationCenter.default.removeObserver(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
//添加外接屏幕链接通知
|
//添加外接屏幕链接通知
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(exScreenWillConnectNotification(notification:)), name: UIScene.willConnectNotification, 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)
|
// 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")
|
self.view.backgroundColor = UIColor(hexString: "#060507")
|
||||||
outputVideoURL = URL.documentsDirectory.appending(path:"output11114.jpg")
|
outputVideoURL = URL.documentsDirectory.appending(path:"output11114.jpg")
|
||||||
@ -207,21 +211,18 @@ class CCSpatialPhotoDisplayController: BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//MARK: - 外接屏幕 链接 与 断开
|
//MARK: - 外接屏幕 链接 与 断开
|
||||||
@objc func exScreenWillConnectNotification(notification:Notification) {
|
@objc func airPlayStatusDidChange(notification:Notification) {
|
||||||
|
|
||||||
|
|
||||||
checkAirPlayStatus()
|
checkAirPlayStatus()
|
||||||
print("外连接。。。。。")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func exScreenDisConnectNotification(notification:Notification) {
|
// @objc func exScreenDisConnectNotification(notification:Notification) {
|
||||||
print("已断开 屏幕。。。。。")
|
// print("已断开 屏幕。。。。。")
|
||||||
|
//
|
||||||
checkAirPlayStatus()
|
// checkAirPlayStatus()
|
||||||
}
|
// }
|
||||||
|
|
||||||
private func checkAirPlayStatus() {
|
private func checkAirPlayStatus() {
|
||||||
print("设备连接变化")
|
print("设备连接变化 photodisplaycontroller>>>>>")
|
||||||
let currentRoute = AVAudioSession.sharedInstance().currentRoute
|
let currentRoute = AVAudioSession.sharedInstance().currentRoute
|
||||||
self.isAirPlayActive = currentRoute.outputs.contains { output in
|
self.isAirPlayActive = currentRoute.outputs.contains { output in
|
||||||
return output.portType == AVAudioSession.Port.HDMI ||
|
return output.portType == AVAudioSession.Port.HDMI ||
|
||||||
@ -232,20 +233,34 @@ class CCSpatialPhotoDisplayController: BaseController {
|
|||||||
func setttinisScreenMirroring(isScreenMirroring:Bool){
|
func setttinisScreenMirroring(isScreenMirroring:Bool){
|
||||||
//已连接
|
//已连接
|
||||||
if(isScreenMirroring){
|
if(isScreenMirroring){
|
||||||
if let screen = UIScreen.screens.last {
|
print("变化为已连接。。。。")
|
||||||
self.externalWindow.screen = screen
|
// 获取所有打开的会话
|
||||||
|
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()
|
let nvc = UIViewController()
|
||||||
self.externalWindow.rootViewController = nvc
|
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
|
imageView.contentMode = .scaleAspectFit
|
||||||
externalImageView = imageView
|
externalImageView = imageView
|
||||||
nvc.view.addSubview(imageView)
|
nvc.view.addSubview(imageView)
|
||||||
self.externalWindow.isHidden = false
|
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)
|
dispalylink?.add(to: RunLoop.main, forMode: RunLoop.Mode.common)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
print("未发现外接屏....")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
print("变化为 断开。。。。")
|
||||||
if let imv = externalImageView{
|
if let imv = externalImageView{
|
||||||
imv .removeFromSuperview()
|
imv .removeFromSuperview()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user