【问题标题】:React to audio being connected & disconnected to an airplay device对连接到播放设备和断开连接的音频做出反应
【发布时间】:2019-11-19 21:32:33
【问题描述】:

我正在寻找一种方法来立即对连接和断开连接到播放设备的音频输出做出反应。 有UIScreen.didConnectNotificationUIScreen.didDisconnectNotification,但只有在控制中心激活镜像时才会通知。

我想在输出被路由到另一台设备时突出显示屏幕上的播放图标。

【问题讨论】:

    标签: ios swift avaudiosession airplay


    【解决方案1】:

    当您在 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 中选择播放设备时更新

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-17
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 2012-10-05
      • 1970-01-01
      相关资源
      最近更新 更多