Iphone MPMoviePlayerViewController在电影结束后问题

Iphone MPMoviePlayerViewController在电影结束后问题,iphone,ios4,Iphone,Ios4,在iOS4 for iPhone4/3GS中,我有一个表视图,其中一个单元格播放一个电影文件。如果电影播放完毕,且控件消失,则视图会在状态栏下返回。就像这张照片…我太新了,无法发布。在这里看到它 如果电影结束时控件处于打开状态,则没有问题 奖励:当电影播放器开始播放时,我如何强制它进入风景区。我根本不想让它出现在肖像中 谢谢。这似乎是4.0中的一个错误,当使用“完成”按钮退出时,它可以正常工作 我使用的解决方法是手动存储帧,然后在收到MPMoviePlayerPlaybackDidFinish

在iOS4 for iPhone4/3GS中,我有一个表视图,其中一个单元格播放一个电影文件。如果电影播放完毕,且控件消失,则视图会在状态栏下返回。就像这张照片…我太新了,无法发布。在这里看到它

如果电影结束时控件处于打开状态,则没有问题

奖励:当电影播放器开始播放时,我如何强制它进入风景区。我根本不想让它出现在肖像中


谢谢。

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

我使用的解决方法是手动存储帧,然后在收到MPMoviePlayerPlaybackDidFinishNotification时将其还原

最后,要在横向模式下使用它,请使用
mpmovieplayervicewcontroller的子类
,在该子类中,您将
应自动旋转指向面方向:(UIInterfaceOrientation)覆盖到交互方向

也就是说,类似这样的事情:

@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];
}

在启动电影播放器之前,我明确声明在我的原始视图上不使用全屏布局,从而解决了这个问题:

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

我也遇到了同样的问题,我已使用此解决方法来解决此问题:

-(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。

@noji接近正确答案。当MPMoviePlayerViewController被解除时,有问题的视图帧正在由iOS设置动画。由于iOS中的一个错误,当播放自动结束时(当电影结束时),动画假定所讨论的视图占据了全屏,但可能没有

第一步。保存包含将启动MPMoviePlayerViewController的视图的superview框架

第二步。为playbackDidFinishNotification附加侦听器

[[NSNotificationCenter defaultCenter] addObserver:self 
                                  selector:@selector(playbackDidFinish:)
                                      name:MPMoviePlayerPlaybackDidFinishNotification 
                                   object:nil];
第三步。在通知处理程序中,将帧重置回原始帧,但在延迟后允许动画完成。如果在动画过程中修改了帧,则不会产生任何效果

[self performSelector:@selector(resetFrame)
           withObject:nil 
           afterDelay:kResetFrameDelay];

- (void)resetFrame {
    self.view.frame = kApplicationFrame;
}

这个问题已经解决,从iOS 4.3开始不再是问题


感谢大家的支持。

如果您仍然有问题,请查看我的解决方案。这在复杂的视图层次结构中不起作用。看看这个-