AirPlay:连接到 Apple TV 时禁用音量控制

AirPlay: volume control is disabled when connected to Apple TV

我正在播客应用中实现 AirPlay 支持。我添加了 AVRoutePickerView,AirPlay 设备加载正常,我可以成功连接到设备。

我正在 Apple TV 上进行测试,音频播放效果很好,但它始终使用最大音量,我无法更改它。音量滑块已禁用,我不明白为什么会这样,因为它在其他应用程序中有效。

例如,我可以在 Overcast 中更改预期的音量,但音频不是以最大音量开始的:

我做错了什么?我是否缺少任何选项。

更新:

我正在使用 AVPlayer 并且 allowsExternalPlayback 属性 是正确的。

更新2:

同样的问题发生在 MPVolumeView

一些 Reddit 用户告诉我“它假设一个人会使用输出设备(电视、音响系统等)的音量控制来控制音量。”,“ 就像当你通过 hdmi 将 MacBook 插入电视时",这是有道理的,但我如何强制不使用输出设备来控制音量?它在其他播客应用程序中的工作方式与我预期的一样。

在与 DTS 工程师讨论后,他找到了解决方法 (rdar://42881405 使用 AirPlay) 连接到 Apple TV 时禁用音量控制。

"According to engineering, the disabling of the volume control is correct behavior for certain Apple TV configurations, where the audio is being sent to the actual TV via HDMI. In that case, volume is controlled by the TV itself.

An alteration to this standard behavior is made for audio-only apps (such as Podcasts and Overcast). In those cases, the volume control is enabled anyway, and it provides a software volume adjustment of the audio in addition to the hardware volume control. The reason you weren’t getting this is that you used AVQueuePlayer, which is regarded as a video player, not a pure audio player. I modified your sample project to use AVAudioPlayer instead, and the volume control was enabled for AirPlay output as expected.

However, AVAudioPlayer cannot play streamed assets, so it may not be a viable solution in your use case. I’m still researching whether the audio-only behavior can be obtained for other playback techniques."

解决方案:

基本上,将 AVPlayer/AVQueuePlayer 的 allowsExternalPlayback 属性 设置为 false 将禁止将视频播放路由到 AirPlay,并且(作为副作用)允许纯音频播放。

最后的注释:

即便如此,我认为使用新的 AVSampleBufferAudioRendererAVSampleBufferRenderSynchronizer 类 也可以,但它们的设置要复杂得多。

rdar://42966681 已创建:提供 API 用于将使用 AVPlayer/AVQueuePlayer 的应用程序指定为“仅音频”.