iPad 3.2& [MPMoviePlayerController setFullScreen:]没有显示出来

时间:2011-04-12 00:29:55

标签: iphone ios ipad mpmovieplayercontroller

我有一个从互联网上播放电影的通用应用程序。它必须支持3.1.x以及4.x。

为了使其工作,我在代码中有一个分支,用于检测3.2之前的设备并使用MPMoviePlayerController,因为它应该在那里工作。

这是我准备玩家播放远程电影的方式:

- (void)registerForMovieNotifications {
    //for 3.2 devices and above
    if ([moviePlayer respondsToSelector:@selector(loadState)]) {
        LOG(@"moviePlayer responds to loadState, this is a 3.2+ device");

        //register the notification that the movie is ready to play
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(moviePlayerLoadStateChanged:)
                                                     name:MPMoviePlayerLoadStateDidChangeNotification
                                                   object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(didExitFullScreen:) 
                                                     name:MPMoviePlayerDidExitFullscreenNotification
                                                   object:nil];

        LOG(@"preparing moviePlayer...");
        [moviePlayer prepareToPlay];



       } else {
            //for pre-3.2 devices
            LOG(@"This is a 3.1.x device");

            //register the notification that the movie is ready to play
            [[NSNotificationCenter defaultCenter] addObserver:self
                                                     selector:@selector(moviePreloadDidFinish:)
                                                         name:MPMoviePlayerContentPreloadDidFinishNotification
                                                       object:nil];
        }

        //handle when the movie finished
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(moviePlayBackDidFinish:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:nil];
    }
    - (void)readyPlayer {
        if (!moviePlayer) {
            moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
        } else {
            [moviePlayer setContentURL:movieURL];
        }

        [self registerForMovieNotifications];
    }

稍后我会收到此通知,并设置电影播放器​​的视图等。

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {
    LOG(@"3.2/4.x - moviePlayerLoadStateChanged:");
    //unless state is unknown, start playback
    if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
        //remove observer
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerLoadStateDidChangeNotification
                                                      object:nil];

        //set the frame of the movie player to match
        self.view.autoresizesSubviews = YES;

        [[moviePlayer view] setFrame:self.view.bounds];
        [[moviePlayer view] setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
        [[moviePlayer view] setAutoresizesSubviews:YES];

        //add movie player as a subview
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES];

        //play the movie
        [moviePlayer play];

    }
}

电影播放。这适用于iPhone 4.2,4.3,iPad 4.2,4.3,但它在iPad 3.2上失败。电影播放但我得到的只是黑屏。

如果我删除[moviePlayer setFullscreen:YES]来电,我会在3.2中看到一部可见的正在播放的电影,但它不是“全屏”,所以它没有完成按钮,我无法解除屏幕

对这里发生的事情有所帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

我能够找到一个可接受的解决方案,但我仍然认为这可能是一个错误。

如果我跳过setFullScreen的来电,而只是手动将controlStyle设置为MPMovieControlStyleFullScreen,那么它会给我一个大致正确的视图(工具栏大约40像素太低) )。

然后我可以获得完成按钮,触发moviePlayer:didFinishPlaying回调。

所以它很臭我现在在我的代码中有一个臭的if 3.2逻辑分支,但希望大多数人都会在4.0上。