Airplay gets disconnected when having several AVPlayer instances, depending on when Airplay is enabled

Originator:defagos
Number:rdar://27171368 Date Originated:05-Jul-2016 03:48 PM
Status:Open Resolved:
Product:iOS SDK Product Version:9.3.2
Classification:Enhancement Reproducible:Always
 
Summary:
Consider an application displaying two videos simultaneously using AVPlayer. The first AVPlayer instance has allowsExternalPlayback set to YES and thus can be displayed on an Airplay receiver, the second player has allowsExternalPlayback set to NO.

The first player plays some main content, while the second one is muted and can be used to watch a second video while the main video is being played. In some way, this is like the PiP functionality of a TV device, but with an off-screen functionality when external playback is enabled.

With this setup, if I enable Airplay first, I can watch the first video on an Airplay receiver (e.g. Apple TV), but as soon as I start playing the second (muted) video Airplay gets disconnected.

If I start both videos before I enable Airplay, the setup perfectly works. I can watch the first video on an Airplay receiver, while having a look at the second video on my device.

Steps to Reproduce:
1. Open the sample project attached to this report. This is a very basic implementation of such a player (with some shortcuts for the sake of simplicity). The application has a single button opening a view with two sibling players on top of the other. The top player only is enabled for external playback, while the bottom player is muted. The players start paused and each player area can be tapped to start playback
2. Connect to a wifi network for which an Airplay receiver is available (e.g. Apple TV)
3. Enable Airplay from the control center. 
4. Open the two-player view and tap on the first video. The video gets displayed on the Airplay device
5. Now tap on the second (muted) video. Airplay gets disconnected

Note that this setup perfectly works if the bottom video is started before Airplay is enabled both videos have started:
1. Disable Airplay
2. Open the view with the two players and tap on both of them to start playback
3. Enable Airplay from the control center
4. Now the first video plays on the Airplay receiver, while the second one plays off-screen. Airplay does not get disconnected

Expected Results:
I would expect finer grained control for Airplay playback when several AVPlayer instances are involved, and a consistent experience whether Airplay is enabled before or after a media gets played. 

FYI, I filed two other tickets describing issues I encountered with Airplay, showing inconsistent behaviour depending on when Airplay is enabled (27170450 and 27079167). All those issues might be related somehow.

Actual Results:
Airplay functionality depends on when it is enabled and is therefore inconsistent.

Version:
iOS 9.3.2

Notes:


Configuration:
iPhone 6

Code sample available at: https://github.com/defagos/radars/tree/master/multiplayer-airplay

Comments


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!