AirPlay in MPMoviePlayerController

490 views Asked by At

I can't get the AirPlay option to show up in my MPMoviePlayerController. It shows up in the command center but I can't get it to show up within my app. I do get an "iPhone Speaker" option (why??) and an "iPhone" option instead of the usual "iPhone" and "AirPlay" options.

This is how I'm initializing my media player:

filePath = [s objectForKey:kStrMergeFileKeyString];
NSURL *movieString = [NSURL fileURLWithPath:filePath];

NSLog(@"filepath %@", filePath);
NSLog(@"fileurl %@", movieString);

// Now set up the movie player controller and play the movie.
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: movieString];

self.moviePlayer = player;
if (self.moviePlayer) {

    [[self.moviePlayer view] setFrame:[self.view bounds]];  // frame must match parent view
    [self.view addSubview: [self.moviePlayer view]];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

    if ([moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) {
        [moviePlayer setAllowsAirPlay:YES];
    }

    self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
    self.moviePlayer.shouldAutoplay = YES;
    [self.moviePlayer play];

    [self.moviePlayer setFullscreen:YES];


} else {
    NSLog(@"Invalid file path");
}

What is going on? Is this a bug?

1

There are 1 answers

0
Lord Sidious On

As of iOS 8.0 Apple has removed the AirPlay button from the controls and is accessible now officially through the control center. If you pull up your control center then you will see the AirPlay button.

That being said, I have created a work around to this by setting the movie player control style to MPMoviePlayerControlStyleNone. After this I created a my own custom UI for the controls with UISliders and UIButtons. Then I set allowsAirPlay to true on the movie player.

You can then use an AirPlayDetector class to check and see if it's available and if so, add the appropriate AirPlay button.

Hope that helps, and I will post code when completely implemented.

Here is the AirPlayDetector github for ARC compliant version.

Cheers!

https://github.com/MobileVet/AirPlayDetector