这就是我为 iOS > 3.2 所做的:
- (void) play {
mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mMovieURL];
if ([mMoviePlayer respondsToSelector:@selector(loadState)])
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinishIOS32:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
[mMoviePlayer prepareToPlay];
[mMoviePlayer play];
mMoviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[mMoviePlayer setMovieControlMode:MPMovieControlModeDefault];
[mMoviePlayer setBackgroundColor:[UIColor clearColor]];
}
}
和
- (void) moviePreloadDidFinishIOS32:(NSNotification*)notification;
{
// Remove observer
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
self.view = mMoviePlayer.view;
}
因此,在 viewdidload 中,您可以实例化您想要的内容(例如 UIActivityIndicatorView)。只有在预加载完成时才会替换视图控制器。