views:

119

answers:

1

In an iphone app, I create an MPMoviePlayerController and instruct it to start playing video in full screen mode (I don't think there is any option for anything but F/S mode on iPhone like you can on ipad).

Once the full screen player comes up, the entire screen is black and there are no controls visible (set to MPMovieControlStyleDefault) for several seconds sometimes.

After a second or three, the controls appear and the first frame of the video, then the video begins to buffer and autoplays correctly.

  1. How can I display a UIActivityIndicator on top of the full screen player? I am displaying the sharedApplication network activity indicator, but I want to show a full size indicator with a "Loading..." label.

I've tried adding it as a subview of the movie player's view, the movie player's background view, as a subview of the movieplayer view's superview (I didn't expect that to work of course). I think the key here is that the F/S movie player view is not the same as the movieplayer's view when not in F/S mode. Yes? Is there a way to access the full screen view?

2.Should the controls be visible (with the DONE button) sooner for a player started in full screen mode? There is a fairly long delay with nothing but black screen when the full screen movie player starts, so the user cant tap the Done button if they become impatient (therefore the only other choice will be exit the app - would prefer to provide an option to cancel the playback if they want.

Thanks in advance!

A: 

If you're not already doing so, register for the MPMoviePlayerLoadStateDidChangeNotification notification (http://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html#//apple_ref/c/data/MPMoviePlayerLoadStateDidChangeNotification) and wait for the MPMoviePlayerController's loadState to change to MPMovieLoadStatePlayable before presenting the movie player.

That way, you can present the activity indicator over your own view until the movie is ready to play. (Be sure to include a way for the user to cancel waiting for the movie.)

In theory, you should be able to add an activity indicator to the MPMovewPlayerController's view, but I've never tried that approach and it sounds like it isn't working for you.

Another option is to add the MPMoviePlayer's view below an existing activity indicator. I successfully just tried this.

[moviePlayer setContentURL:trailer.downloadLink];
moviePlayer.fullscreen = YES;
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer prepareToPlay];

[self.navigationController.view addSubview:self.activityIndicator];
self.activityIndicator.center = self.navigationController.view.center;
[self.activityIndicator startAnimating];

moviePlayer.view.frame = self.navigationController.view.bounds;
[self.navigationController.view insertSubview:moviePlayer.view belowSubview:self.activityIndicator];

Here are my notification handlers.

#pragma mark MPMoviePlayerController notifications

- (void)moviePlayerLoadStateChanged:(NSNotification *)notif
{
    NSLog(@"loadState: %d", moviePlayer.loadState);
    if (moviePlayer.loadState & MPMovieLoadStateStalled) {
        [self.activityIndicator startAnimating];
        [moviePlayer pause];
    } else if (moviePlayer.loadState & MPMovieLoadStatePlaythroughOK) {
        [self.activityIndicator stopAnimating];
        [moviePlayer play];

    }
}

- (void)moviePlayerPlaybackFinished:(NSNotification *)notif
{
    [moviePlayer.view removeFromSuperview];
    [self.activityIndicator stopAnimating];
}
Robot K
Sounds like you are saying to defer adding the movie player view to the view hierarchy until the load state is MPMovieLoadStatePlayable. I'll try it - I didn't think of that. I assume the movie player will begin to buffer, etc. even if it is not added to the view hierarchy.
Jordan Bigel
Exactly. That's how I've done it in the past.
Robot K