How to show “Loading Movie…” message with MPMovieP

2019-05-07 03:34发布

问题:

I'm working with the MPMoviePlayerController for the iOS platform and am not sure why the "Done" and "Loading Movie..." controls are not displaying automatically when loading a new video.

My original implementation of this was to use the UIWebView control to stream the videos, and when the videos are accessed, the "Done" and "Loading Movie..." controls are displayed until the video is loaded and ready to play. I would like to reproduce the same user experience with the MPMoviePlayerController.

Should I get the "Done" and "Loading Movie..." control overlays for free? If not, what do I have to set to get them to show up while the video is loading?

NSURL *videoUrl = [NSURL URLWithString:urlString];
self.moviePlayer = [[[MPMoviePlayerController alloc] init] autorelease];
self.moviePlayer.movieControlMode = MPMovieControlModeDefault;

[self.moviePlayer setContentURL:videoUrl];
[self.moviePlayer prepareToPlay];

[self.view addSubview:self.moviePlayer.view]; 
[[self.moviePlayer view] setFrame: [self.view bounds]];
[self.moviePlayer setFullscreen:YES animated:YES];

回答1:

This is answer to your follow-up question, but anyways... You can speed-up things a little bit with this:

prepareToPlay
Prepares the current item for playback. (required)

- (void)prepareToPlay  

This method is called automatically when you call the play method. Calling it before you call play gives the receiver a chance to prepare items sooner and may result in decreased latency when starting playback. However, calling this method may also interrupt any active audio sessions.

Available in iOS 3.2 and later. Declared In MPMediaPlayback.h