如何在MPMoviePlayerController中更改“正在加载电影...”消息?

时间:2009-10-18 13:39:27

标签: iphone mpmovieplayercontroller

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

1 个答案:

答案 0 :(得分:2)

您可以使用要显示的图像(或标签或其他任何内容)创建一个UIImageView,并将其添加到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];

然后您可以实例化电影播放器​​并注册以在loadState更改时接收通知:

moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:movie.trailerURL];

if ([moviePlayer respondsToSelector:@selector(loadState)]) {

        [moviePlayer prepareToPlay];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];}  

然后在您的通知方法中,执行逻辑以将播放器添加到视图中:

- (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];
                        ...
}