How can I change the "Loading Movie..." message in MPMoviePlayerController?
When 开发者_如何学CI launch an instance of MPMoviePlayerController for a remote URL, the top bar displays "Loading Movie..." - is there a way to change this message to a custom one?
You can simply create a UIImageView with an image that you want to display (or label or whatever else) and add it to your MoviePlayerControllerView.
UIImage *loadingScreenImage = [UIImage imageNamed:@"loadingScreen.png"];
loadingScreen = [[UIImageView alloc] initWithImage:loadingScreenImage]; // ivar & property are declared in the interface file
[self.view addSubview:loadingScreen];
[loadingScreen release];
Then you can instantiate the movie player and register to receive a notification when loadState changes:
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movie.trailerURL];
if ([moviePlayer respondsToSelector:@selector(loadState)]) {
[moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];}
Then in your notification method, do the logic to add the player to the view:
- (void) moviePlayerLoadStateChanged:(NSNotification*)notification
{
// Unless state is unknown, start playback
switch ([moviePlayer loadState]) {
case MPMovieLoadStateUnknown:
break;
case MPMovieLoadStatePlayable:
// Remove observer
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
// Set frame of movie player
[moviePlayer.view setFrame:CGRectMake(0, 0, 480, 320)];
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayer setFullscreen:YES animated:YES];
[self.view addSubview:[moviePlayer view]];
// Play the movie
[moviePlayer play];
...
}
精彩评论