【问题标题】:MPMoviePlayerViewController issue after movie finishes电影完成后的 MPMoviePlayerViewController 问题
【发布时间】:2010-07-22 16:08:00
【问题描述】:

在 iPhone 4/3GS 的 iOS4 中,我有一个表格视图,其中一个单元格播放电影文件。如果电影播放完毕并且控件消失,则视图会返回到状态栏下方。就像在这张图片中......我太新了,不能发布。看这里...

http://www.dezignwright.com/ios4_movie.png

如果影片结束时控件打开,则没有问题。

奖励:我如何在电影播放器​​开始播放时强制它进入横向。我根本不希望它以纵向播放。

谢谢。

【问题讨论】:

    标签: iphone ios4


    【解决方案1】:

    @Nuoji 接近正确答案。当 MPMoviePlayerViewController 被解除时,iOS 正在为相关视图的框架设置动画。由于 iOS 中的一个错误,当播放自动结束时(当电影结束时),动画假定有问题的视图占据了全屏,而实际上可能不会。

    步骤 1. 保存包含将启动 MPMoviePlayerViewController 的视图的超级视图的框架。

    第 2 步. 为 PlaybackDidFinishNotification 附加监听器

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                      selector:@selector(playbackDidFinish:)
                                          name:MPMoviePlayerPlaybackDidFinishNotification 
                                       object:nil];
    

    第 3 步。在通知处理程序中,将帧重置为原始帧,但要经过延迟以允许动画完成。如果在动画期间修改了帧,则没有效果。

    [self performSelector:@selector(resetFrame)
               withObject:nil 
               afterDelay:kResetFrameDelay];
    
    - (void)resetFrame {
        self.view.frame = kApplicationFrame;
    }
    

    【讨论】:

      【解决方案2】:

      此问题已得到解决,自 iOS 4.3 起不再是问题。

      感谢大家的意见。

      【讨论】:

        【解决方案3】:

        这似乎是 4.0 中的一个错误,使用“完成”按钮退出时它可以正常工作。

        我使用的解决方法是手动存储框架,然后在收到MPMoviePlayerPlaybackDidFinishNotification 时恢复它。

        最后要让它进入横向模式,使用 MPMoviePlayerViewController 的子类覆盖 shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

        即像这样:

        @interface CustomMoviePlayerViewController : MPMoviePlayerViewController
        @end
        @implementation CustomMoviePlayerViewController
        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
        {
            return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft;
        }
        @end
        

        并在您的控制器中解决该错误:

        - (void)playbackEnded:(NSNotification *)notification
        {
            [[self view] setFrame:[self originalFrame]];
        }
        
        - (void)playMovie:(NSString *)movieURLString
        {
            MPMoviePlayerViewController *controller = [[CustomMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movieURLString]];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackEnded:) name:MPMoviePlayerPlaybackDidFinishNotification object:[controller moviePlayer]];
            [self presentMoviePlayerViewControllerAnimated:controller];
        }
        

        【讨论】:

        • 如果您仍有问题,请查看我的解决方案
        【解决方案4】:

        我通过在启动电影播放器​​之前明确声明我不在原始视图上使用全屏布局来解决该问题:

        -(IBAction)playMovieButtonPressed:(id)sender { 
            MPMoviePlayerViewController* playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[self localMovieURL]];
            [[NSNotificationCenter defaultCenter] addObserver:self 
                    selector:@selector(playbackDidFinish:) 
                     name:MPMoviePlayerPlaybackDidFinishNotification 
                      object:playerViewController.moviePlayer];
        
         [self setWantsFullScreenLayout:NO]; 
         // this ensures that the original frame is restored correctly 
         // if the movie ends and the player is closed automatically
        
         [self presentMoviePlayerViewControllerAnimated:playerViewController];
            [playerViewController release];
            MPMoviePlayerController *player = [playerViewController moviePlayer];
            [player play];
        }

        【讨论】:

        【解决方案5】:

        我遇到了同样的问题,我使用了这个解决方法来解决这个问题:

        -(void)myMovieFinishedCallback:(NSNotification*)aNotification
        {
            if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
                CGRect frame = CGRectMake(0, 20, 768, 1004);
                self.view.frame = frame;
            }else {
                CGRect frame = CGRectMake(0, 20, 1004, 768);
                self.view.frame = frame;
            }
        }
        

        将 Rect 调整为您的屏幕尺寸,我的代码应该适用于 iPad。

        【讨论】:

          猜你喜欢
          • 2017-02-27
          • 1970-01-01
          • 2012-05-14
          • 1970-01-01
          • 2012-04-06
          • 2015-10-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多