iPad 3.2 & [MPMoviePlayerController setFullScreen:] 没有出现

Posted

技术标签:

【中文标题】iPad 3.2 & [MPMoviePlayerController setFullScreen:] 没有出现【英文标题】:iPad 3.2 & [MPMoviePlayerController setFullScreen:] not showing up 【发布时间】:2011-04-12 00:29:55 【问题描述】:

我有一个通用应用程序,可以播放互联网上的电影。它必须支持 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 中看到一个正在播放的电影,但它不是“全屏”,因此它没有“完成”按钮,我无法关闭屏幕。

我希望喜欢一些关于这里发生的事情的帮助。谢谢!

【问题讨论】:

希望我有一台运行 3.2 的设备来为您测试。它看起来确实可能是 3.2 中的错误。您是否尝试致电setFullscreen:animated:,以防万一? 从通知处理程序中删除所有视图处理。只保留moviePlayer 播放方法。早点做那些特定于视图的事情。 hth @Nathan - 是的,我确实尝试过 :) 【参考方案1】:

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

如果我跳过对setFullScreen 的调用,而只是手动将controlStyle 设置为MPMovieControlStyleFullScreen,那么它给我的视图大部分是正确的(工具栏太低了大约40 像素)。

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

所以我现在在我的代码中有一个臭的 if 3.2 逻辑分支,但希望大多数人无论如何都会使用 4.0。

【讨论】:

以上是关于iPad 3.2 & [MPMoviePlayerController setFullScreen:] 没有出现的主要内容,如果未能解决你的问题,请参考以下文章

Android&Quickblox (api 3.2):订阅推送通知

Scrum 3.2 多鱼点餐系统开发进度(页面优化&下单详细信息页面)

[课程设计]Scrum 3.2 多鱼点餐系统开发进度(页面优化&下单详细信息页面)

3.2

来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能

来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能