Opting Into or Out of AirPlay

Audio content (except for system sounds) and media played via iTunes or the Music app are always available to AirPlay. Video playing in your app or from your website can be enabled for AirPlay or not, at your discretion.

Before iOS 5.0, you needed to opt into AirPlay to enable your media to be played over Apple TV. In apps compiled with the base SDK set to iOS 5.0 and later, AirPlay is enabled by default; if you do not want iOS-based devices to be able to play your video over Apple TV, you must disable AirPlay explicitly.

In iOS 5.0 and later, Safari opts in for web content by default.

Enabling or Disabling AirPlay on Your Website

To enable video on your website to be viewable via AirPlay, embed it in your webpage using the HTML5 <video> tag. See Safari HTML5 Audio and Video Guide for details.

To explicitly opt in to AirPlay, set the x-webkit-airplay attribute for the video tag or the airplay attribute for the embed tag to "allow", as shown in Listing 2-1.

Listing 2-1  Allowing AirPlay to use your video

<video src="myPlaylist.m3u8"
       height="300" width="400"
       x-webkit-airplay="allow" >
 
  <embed airplay=”allow”
       src="movie.mov"
       width=400
       height=300
       mime-type="video/quicktime">
  </embed>
 
</video>

To explicitly opt out of AirPlay, set x-webkit-airplay attribute for the video tag or the airplay attribute for the embed tag to "deny", as shown in Listing 2-2.

Listing 2-2  Disallowing AirPlay to use your video

<video src="myPlaylist.m3u8"
       height="768" width="1024"
       x-webkit-airplay="deny" >
 
</video>
 
<!-- or -->
 
<embed airplay="deny"
       src="movie.mov"
       width=320
       height=240
       mime-type="video/quicktime">
 
</embed>

Enabling or Disabling AirPlay in Your App

AirPlay is automatically enabled for video when your app uses AV Foundation, the MPMoviePlayerController class, or the UIWebView class to display video. If necessary, you can explicitly disable AirPlay for your app’s video. The exact method depends on the API you use for video playback.

If Your App Uses AVPlayer

If Your App Uses MPMoviePlayerController

If Your App Uses UIWebView