【问题标题】:Detect the AirPlay Device Type iPhone is Connected To检测 iPhone 连接到的 AirPlay 设备类型
【发布时间】:2020-01-04 00:18:28
【问题描述】:

有没有办法获取 iPhone 连接的 AirPlay 设备类型?例如,有没有办法知道 iPhone 通过 AirPlay 连接到 HomePod、Apple TV 或 AirPods?我想在我的应用程序中显示 iPhone 连接到的设备的图标(我提供图标)。我已经在某种程度上实现了这一点

let currentRoute = AVAudioSession.sharedInstance().currentRoute
let output = currentRoute.outputs.first!
let portType = output.portType

AVAudioSession.Port 仅包含airPlay 类型(请参阅所有属性类型的链接)。它不包含homepodappleTV.airpods 等内容。有没有人可以解决这个问题或任何想法?

【问题讨论】:

  • developer.apple.com/documentation/avfoundation/… -> 使用属性 portName ,如果这是正在使用的硬件,它将显示或包含“AirPods”。
  • @SeanMcDonald 遗憾的是,这也不起作用。对于 HomePod 或 Apple TV,端口名称为“Speaker”。

标签: ios swift avaudiosession airplay


【解决方案1】:

我自己也碰到过这个,除了检查当前AVAudioSession的AVAudioSession.Port.airPlay外,还需要检查AVPlayer的isExternalPlaybackActive属性的值。如果是真的,那就是 AirPlaying 视频,如果不是,它只是将音频发送到 HomePod 或耳机。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    • 2021-05-08
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    相关资源
    最近更新 更多