首页 文章

MPMoviePlayerController在全屏模式下停止工作//纵向// iOS 7

提问于
浏览
6

在我的项目中,我使用embeded视图,里面有MPMoviePlayerController .

点击全屏切换后,此电影播放器停止工作 - 在全屏模式下再播放1秒,然后停止并返回到内联模式 .

它仅在纵向模式下发生,仅适用于iOS 7 - 如果我以横向打开全屏模式然后旋转设备,它可以正常工作 .

我找到了原因 - 不知何故涉及导航栏 . 我在项目中使用了ECSlidingViewController并在初始化过程中设置了半透明的导航栏"NO":

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController];

navController.navigationBar.translucent = NO;

self.topViewController = navController;

如果我设置 navController.navigationBar.translucent = YES; ,电影播放器工作正常 . 但我必须有半透明= NO .

所以我试着玩电影播放器事件MPMoviePlayerWillEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification . 有趣的是,如果我在进入全屏模式之前使navBar半透明或隐藏它,视频播放时间会更长(大约3-4秒),但行为是相同的 .

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillEnterFullScreen:)
                                                 name:MPMoviePlayerWillEnterFullscreenNotification
                                               object:nil];


-(void)moviePlayerWillEnterFullScreen:(id)sender{

    [self.navigationController setNavigationBarHidden:YES animated:NO]; 

OR
    self.navigationController.navigationBar.translucent = YES;
}

我对此能做的任何想法都非常感激 .

UPD. 此错误在iOS 7.0.4中消失了

1 回答

  • 3

    IMP:如果你正在使用ARC,我相信你需要保留外部的moviePlayer . 我自己就把它分配给了一个新的房产 .

    我尝试了两种方式,它为我工作 .

    如果您使用自我视图作为整个屏幕 .

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform,          CGAffineTransformMakeRotation(M_PI_2));
    [moviePlayer.view setFrame: self.view.bounds];
    [self.view addSubview: moviePlayer.view];
    [moviePlayer play];
    

    并且不使用自我视图,您可以使用整个全屏(它不会调用全屏属性)

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform,   CGAffineTransformMakeRotation(M_PI_2));
    UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
    [moviePlayer.view setFrame:backgroundWindow.frame];
    [backgroundWindow addSubview:moviePlayer.view];
    [moviePlayer play];
    

相关问题