Volume control is disabled when connected to Apple TV using AirPlay

Originator:ricardopereira.eu
Number:rdar://42881405 Date Originated:03-Aug-2018 01:44 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:11.4.1
Classification:Other Bug Reproducible:Always
 
Summary:
It's like a Podcast app. AirPlay devices are loading fine and I can connect to a device successfully. I'm testing in an Apple TV and the audio plays well but it's using always the max volume and I can't change it in the iPhone. The volume slider from AVRoutePickerView is disabled and I can't understand why that's happening because it works well in other apps like Podcasts.app.

Steps to Reproduce:
Add an AVRoutePickerView to the view of an UIViewController. Setup AVAudioSession with AVAudioSessionCategoryPlayback, AVAudioSessionModeDefault and LongForm Route Sharing Policy, add an AVPlayer with a remote file (AVPlayerItem(url: url)), start playback, update MPNowPlayingInfoCenter with MPNowPlayingInfoMediaType.audio and other info. Don't forget to setup MPRemoteCommandCenter as well.

Expected Results:
Volume control to be enabled and volume hardware buttons functional. Be able to control the volume of the external device from the iPhone.

Actual Results:
Volume control in `MPAudioRoutingPicker` is disabled. It’s not possible to change the volume from the hardware buttons too. The app always outputs at full volume, which requires that I adjust the volume at the destination speaker

Version:
11.4.1

Notes:
Attachment a focused Xcode project operates differently from all other apps (like Podcasts.app) in this regard. When broadcasting to an AirPlay device like an Apple TV, I'm unable to control the volume from the iPhone. The app always outputs at full volume, which requires that I adjust the volume at the destination speaker (which users don't want to, they don't want to walk to the destination speaker to lower (or in some cases raise) the output volume).

Comments

ricardopereira.eu

Please assume this bug has an enhancement request: provide an API for designating an app using AVPlayer/AVQueuePlayer as “audio-only”.

By ricardopereira.eu at Aug. 6, 2018, 1:26 p.m. (reply...)

ricardopereira.eu

Even so, I think that using the new AVSampleBufferAudioRenderer and AVSampleBufferRenderSynchronizer classes would also work but are way more complex to setup.

By ricardopereira.eu at Aug. 6, 2018, 1:22 p.m. (reply...)

ricardopereira.eu

After discussion with a DTS Engineer, he found a workaround.

"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."

Basically, setting allowsExternalPlayback property of an AVPlayer/AVQueuePlayer to false will disallow the routing of video playback to AirPlay, and (as a side-effect) allows the pure audio playback.

By ricardopereira.eu at Aug. 6, 2018, 1:22 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!