1

当我为远程 URL 启动 MPMoviePlayerController 实例时,顶部栏显示“正在加载电影...” - 有没有办法将此消息更改为自定义消息?

4

1 回答 1

2

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];
                        ...
}
于 2010-12-04T10:32:32.087 回答