Enable or Disable Airplay

PDF for offline use:
Sample Code:
Related SDKs:

Let us know how you feel about this.


0/250
Thanks for the feedback!

This recipe shows how to enable (or disable) AirPlay when playing a video using MPMoviePlayerController.

Recipe

Note: In iOS 8 and above, the airplay button will no longer appear in playback controls. Airplay can be enabled or disabled in the control center.
  • Add the following class variable in a UIViewController subclass:
MPMoviePlayerController moviePlayer;
  • Add a movie file named sample.m4v to the project in Xamarin or Visual Studio. There is a sample file included in the example project.
  • Ensure that the Build Action property of the file is set to Content.
  • In the ViewDidLoad method, create the MPMoviePlayer:
moviePlayer = new MPMoviePlayerController (NSUrl.FromFilename("sample.m4v");
moviePlayer.View.Frame = View.Bounds;
moviePlayer.ShouldAutoplay = true; // starts automatically
moviePlayer.PrepareToPlay (); //required to enable the control to start playing
  • To enable AirPlay for this movie, set AllowsAirPlay to true:
moviePlayer.AllowsAirPlay = true;
  • To disable AirPlay, set AllowsAirPlay to false:
moviePlayer.AllowsAirPlay = false;

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.