0

How do I show a button on an AVPlayer layer allowing a user to opt into AirPlay?

In the old days, I would simply add an MPVolumeView as a subview, and this would show an airplay button that a user could use to toggle. Now, it seems like a volume view ONLY shows the airplay toggle if the user has opted in via mirroring on control center. Even then, that toggle simply allows them to switch routes or opt back out, and promptly disappears when they do. I can't even get an AVPlayer later to show an airplay toggle under any other condition.

Netflix seems to have the same (broken imo)functionality. Does Apple really expect users to only opt into airplay from control center? Does anyone know a hack or undocumented API to bring back the old functionality?

StevenOjo
  • 2,498
  • 1
  • 16
  • 21
  • `MPVolumeView` is still there with same functionality. https://developer.apple.com/reference/mediaplayer/mpvolumeview – Ryan Mar 21 '17 at 21:46
  • Yes, however when you use it, it doesn't work as expected. It only shows the AirPlay button if you opt into airplay via mirroring. – StevenOjo Mar 21 '17 at 21:54
  • Actually it will be appeared when there's `AirPlay` able device in the same network. – Ryan Mar 21 '17 at 21:59
  • Nope, here are the screenshots: Here's the view on the same wifi, with mirroring disabled: http://imgur.com/a/gL4LN – StevenOjo Mar 21 '17 at 22:09
  • Now, once the user enables mirroring from the control center - it looks like this: http://imgur.com/a/R0czX Before, it used to toggle and show the AirPlay button in white before a user opted into airplay. – StevenOjo Mar 21 '17 at 22:10

1 Answers1

0

Well, I solved my own question:

Restarting my AppleTV and my iPhone caused this work as expected, with no code changes. It still seems to be intermittent, but I assume this is some sort of apple bug.

I'll post an undocumented approach that works more reliably if I find one.

StevenOjo
  • 2,498
  • 1
  • 16
  • 21