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.
- 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!
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];
}
I didnt like the fact to display activityIndicator in the center of the screen because the movie player already owns one. I rather display it on the top toolbar :
-(void)activityIndicatorAnimate :(int)action
{
if (action == 0) {
/* STOP ANIMATING ACTIVITY INDICATOR */
if (activityIndicator != nil) {
[[self navigationItem] setRightBarButtonItem:nil];
[activityIndicator stopAnimating];
[activityIndicator release];
activityIndicator = nil;
}
NSLog(@"Stop activityIndicator");
} else if (action == 1) {
/* START ANIMATING ACTIVITY INDICATOR */
if (activityIndicator == nil) {
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[[self navigationItem] setRightBarButtonItem:barButton];
[barButton release];
NSLog(@"Start activityIndicator");
}
[activityIndicator startAnimating];
}
}
精彩评论