diff --git a/SwiftProject/SwiftProject/CCKit/Add/UIColor+Add.swift b/SwiftProject/SwiftProject/CCKit/Add/UIColor+Add.swift index 8d9b6e4..879669d 100644 --- a/SwiftProject/SwiftProject/CCKit/Add/UIColor+Add.swift +++ b/SwiftProject/SwiftProject/CCKit/Add/UIColor+Add.swift @@ -60,6 +60,10 @@ extension UIColor { return UIColor.init(red: _r/255, green: _g/255, blue: _b/255, alpha: alpha) } + class func colorWithRGBINT(_r:Int , _g:Int , _b:Int) -> UIColor{ + return UIColor.init(red: CGFloat(_r)/255, green: CGFloat(_g)/255, blue: CGFloat(_b)/255, alpha: 1.0) + } + } diff --git a/SwiftProject/SwiftProject/Project/Controller/CCHomeController.swift b/SwiftProject/SwiftProject/Project/Controller/CCHomeController.swift index 3f24959..3dedc9e 100644 --- a/SwiftProject/SwiftProject/Project/Controller/CCHomeController.swift +++ b/SwiftProject/SwiftProject/Project/Controller/CCHomeController.swift @@ -61,40 +61,45 @@ class CCHomeController: BaseController, LLCycleScrollViewDelegate { self.navigationController?.tabBarController!.tabBar.isTranslucent = true; self.setNavgationBarColor(color: UIColor.clear) + self.checkAirPlayStatus() } - func isExternalDeviceConnected() -> Bool { - let screens = UIScreen.screens - - // 如果屏幕数量大于1,则至少连接了一个外部设备 - if screens.count > 1 { - return true - } - - // 检查每个屏幕是否是外部屏幕 - for screen in screens { - if !screen.isEqual(UIScreen.main) { - return true - } - } - - // 没有连接外部设备 - return false - } +// func isExternalDeviceConnected() -> Bool { +// let screens = UIScreen.screens +// +// // 如果屏幕数量大于1,则至少连接了一个外部设备 +// if screens.count > 1 { +// return true +// } +// +// // 检查每个屏幕是否是外部屏幕 +// for screen in screens { +// if !screen.isEqual(UIScreen.main) { +// return true +// } +// } +// +// // 没有连接外部设备 +// return false +// } override func viewDidLoad() { super.viewDidLoad() + self.view.backgroundColor = UIColor.black self.navLine?.isHidden = true - let isExternalDeviceConnected = isExternalDeviceConnected() +// let isExternalDeviceConnected = isExternalDeviceConnected() - if isExternalDeviceConnected { - let deviceName = UIDevice.current.name - print("已连接外部设备,设备名称:\(deviceName)") - } else { - print("未连接外部设备") - } +// if isExternalDeviceConnected { +// let deviceName = UIDevice.current.name +// print("已连接外部设备,设备名称:\(deviceName)") +// } else { +// print("未连接外部设备") +// } + + // 监听 AirPlay 设备的连接状态 + NotificationCenter.default.addObserver(self, selector: #selector(airPlayStatusDidChange(_:)), name: AVAudioSession.routeChangeNotification, object: nil) //393*236 mTopImgView = UIImageView(frame: CGRect(x: 0, y: 0, width: SCREEN_Width, height: SCREEN_Height * 236/393)) @@ -148,12 +153,33 @@ class CCHomeController: BaseController, LLCycleScrollViewDelegate { mTopCenterBtn!.setTitle("未连接VR设备", for: UIControl.State.normal) mTopCenterBtn!.setTitleColor(UIColor.white, for: UIControl.State.normal) mTopCenterBtn!.titleLabel?.font = UIFont.systemFont(ofSize: 12) - + mTopCenterBtn!.isEnabled = false centerView() bottomButton() } + //MARK: - 监听设备投流 + @objc private func airPlayStatusDidChange(_ notification: Notification) { + checkAirPlayStatus() + } + + private func checkAirPlayStatus() { + print("设备连接变化") + let currentRoute = AVAudioSession.sharedInstance().currentRoute + let isAirPlayActive = currentRoute.outputs.contains { output in + return output.portType == AVAudioSession.Port.HDMI || + output.portType == AVAudioSession.Port.airPlay + } + + mTopCenterBtn!.setTitle((isAirPlayActive ? "已连接外部设备" : "未连接VR设备"), for: UIControl.State.normal) + mTopCenterBtn!.backgroundColor = isAirPlayActive ? UIColor.colorWithRGBINT(_r: 73, _g: 34, _b: 208) : UIColor.hexStringToColor(hexString: "#060507") + isAirPlayActive ? mTopCenterBtn!.setImage(UIImage.init(named: "linked_button"), for: .normal) : mTopCenterBtn!.setImage(nil,for: .normal) + isAirPlayActive ? mTopCenterBtn!.updateBtnEdgeInsets(style: .Left, space: 5):mTopCenterBtn!.updateBtnEdgeInsets(style: .Left, space: 0) + + } + + func centerView(){ //345*200 diff --git a/tdvideo/tdvideo.xcodeproj/project.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate b/tdvideo/tdvideo.xcodeproj/project.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate index 72019b0..432bd10 100644 Binary files a/tdvideo/tdvideo.xcodeproj/project.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate and b/tdvideo/tdvideo.xcodeproj/project.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate differ