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

标签 ios avfoundation avplayer airplay

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

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

enter image description here

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

enter image description here

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

更新:

我正在使用 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 的应用指定为“纯音频”

关于ios - AirPlay:连接到 Apple TV 时禁用音量控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51596277/

相关文章:

objective-c - 错误 : 'row" undeclared UI Picker

ios - Phonegap CLI 5.1.1 --变量未显示在plugin.xml中

ios - 停止 AVPlayer 并重新启动 MP3 文件

ios - Swift - 如何在按下不同 UITableView 单元格中的另一个播放按钮时自动停止当前播放的音频?

html - 无法通过 NSAttributedString 使 <img> 适合 UITextView/HTML 中的屏幕宽度

ios - 无法使用(swift3 xcode9 iOS)解析标识符 socketmanager

ios - 使用 AVFoundation 在顶部创建具有自定义背景颜色和适合纵横比的视频的方形视频

ios - 在 Swift 中使用 AVFoundation 拍摄照片

ios - 如何从同一个 AVCaptureSession 捕获照片和视频?

ios - AVPlayer seekToTime : backward not working