in iOS

How to enable iOS AirPlay in AVPlayer layer

MPMoviePlayerController is the goto solution for a quick implementation of a video player in your iOS apps.

But sometimes, you want more control on the movie playing experience, that’s why there’s the AVPlayer. From what I understand, MPMoviePlayerController wraps AVPlayer for easy access, but if you want your own custom controls, skins, colours, whatever its best to use AVPlayer.

One thing about AVPlayer is that you have to build it a user interface in order for it to be as useful as MPMoviePlayerController.

In my GitHub I’ve put a full example of how to do this:

Most controls are straight forward to implement, from current timestamp to play/pause functionality there’s a lot of example code on the web to do this.

One missing feature is Airplay support. Turns out its very easy to implement:

MPVolumeView *volumeView = [ [MPVolumeView alloc] init] ;
[volumeView setShowsVolumeSlider:NO];
[volumeView sizeToFit];
 
// View is where you'll be displaying the AirPlay icon/picker
[view addSubview:volumeView];

reference: Apple
Let me know what you think. cheers!

Update: Check out how to receive notifications on AirPlay status change