【发布时间】:2019-11-19 21:32:33
【问题描述】:
我正在寻找一种方法来立即对连接和断开连接到播放设备的音频输出做出反应。
有UIScreen.didConnectNotification和UIScreen.didDisconnectNotification,但只有在控制中心激活镜像时才会通知。
我想在输出被路由到另一台设备时突出显示屏幕上的播放图标。
【问题讨论】:
标签: ios swift avaudiosession airplay
我正在寻找一种方法来立即对连接和断开连接到播放设备的音频输出做出反应。
有UIScreen.didConnectNotification和UIScreen.didDisconnectNotification,但只有在控制中心激活镜像时才会通知。
我想在输出被路由到另一台设备时突出显示屏幕上的播放图标。
【问题讨论】:
标签: ios swift avaudiosession airplay
当您在 StackOverflow 上发帖时,您就会找到解决方案。
注册MPVolumeViewWirelessRouteActiveDidChange:
NotificationCenter.default.addObserver(self,
selector: #selector(checkForAirplayRouting),
name: NSNotification.Name.MPVolumeViewWirelessRouteActiveDidChange,
object: nil)
let volumeView: MPVolumeView!
@objc func checkForAirplayRouting() {
//print(#function)
volumeView.tintColor = volumeView.isWirelessRouteActive ? UIColor.orange : UIColor.white
}
这将在用户在 MPVolumeView 中选择播放设备时更新
【讨论】: