简体   繁体   English

MPMoviePlayerPlaybackDidFinishNotification中的Segue直到第二次才触发

[英]Segue in MPMoviePlayerPlaybackDidFinishNotification does no fire till second time

Just upgraded a project from iOS5 to iOS7. 刚刚将项目从iOS5升级到了iOS7。 For a reason I can not fathom the video now plays twice before the segue works 由于某种原因,我无法理解视频现在可以在segue播放之前播放两次

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    NSLog(@"LogoVC viewDidAppear");

    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"start_sting_logo_resolve" ofType:@"mp4"];
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayerController];

    // no moviecontrolls
    moviePlayerController.controlStyle = MPMovieControlStyleNone;

    [self.view addSubview:moviePlayerController.view];
    moviePlayerController.fullscreen = YES;
    moviePlayerController.scalingMode = MPMovieScalingModeAspectFill;
    moviePlayerController.view.backgroundColor = [UIColor whiteColor];
    [moviePlayerController play];
}


#pragma mark - Video methods


- (void)moviePlaybackComplete:(NSNotification *)notification
{
    NSLog(@"moviePlaybackComplete");
    MPMoviePlayerController *moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayerController];

    [moviePlayerController.view removeFromSuperview];
    [moviePlayerController release];

    [self performSegueWithIdentifier:@"segueToScroller" sender:self];
    NSLog(@"preformed performSegueWithIdentifier");
}

The view loads twice according to the log 视图根据日志加载两次

2014-07-01 14:25:17.872 Appname[1620:60b] LogoVC viewDidAppear
2014-07-01 14:25:31.745 Appname[1620:60b] moviePlaybackComplete
2014-07-01 14:25:31.766 Appname[1620:60b] LogoVC viewDidAppear
2014-07-01 14:25:31.965 Appname[1620:60b] preformed performSegueWithIdentifier
2014-07-01 14:25:44.089 Appname[1620:60b] moviePlaybackComplete
2014-07-01 14:25:44.124 Appname[1620:60b] preformed performSegueWithIdentifier
2014-07-01 14:25:44.190 Appname[1620:60b] ScrollerVC viewDidLoad

The video file is local. 视频文件是本地的。

MPMoviePlayerPlaybackDidFinishNotification is firing, but instead of the segue being performed, the viewcontroller seems to reload, and only the segue only woks the second time MPMoviePlayerPlaybackDidFinishNotification is called. MPMoviePlayerPlaybackDidFinishNotification正在触发,但不是执行segue,而是重新加载了视图控制器,并且只有segue才第二次调用MPMoviePlayerPlaybackDidFinishNotification时才唤醒。

It's custom segue if that makes any difference 如果这有什么区别,那就是自定义segue

#import "JBCustomSegue.h"

@implementation JBCustomSegue

- (void) perform {

    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

    int orient = [UIApplication sharedApplication].statusBarOrientation;

    if (orient==3){
        // Orient for Landscape Right 4
        [UIView transitionWithView:src.navigationController.view duration:0.3
                           options:UIViewAnimationOptionTransitionCurlUp
                        animations:^{[src.navigationController pushViewController:dst animated:NO];} completion:NULL];


    } else if (orient==4) {
        // Orient for Landscape Left 3
        [UIView transitionWithView:src.navigationController.view duration:0.3
                           options:UIViewAnimationOptionTransitionCurlDown
                        animations:^{[src.navigationController pushViewController:dst animated:NO];} completion:NULL];
    } else {
        // Orient for Landscape Right 4
        [UIView transitionWithView:src.navigationController.view duration:0.3
                           options:UIViewAnimationOptionTransitionCurlDown
                        animations:^{[src.navigationController pushViewController:dst animated:NO];} completion:NULL];
    }
}

The thing is this didn't happen per-iOS7 事实是,这并不是每个iOS7都发生的

The culprit seems to be _moviePlayerController.fullscreen = YES; 罪魁祸首似乎是_moviePlayerController.fullscreen = YES;

I added the screen dimensions instead with [_moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)]; 我用[_moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)];添加了屏幕尺寸[_moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)];

NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"start_sting_logo_resolve" ofType:@"mp4"];
NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];

_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlaybackComplete:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:_moviePlayerController];

// no moviecontrolls
_moviePlayerController.controlStyle = MPMovieControlStyleNone;

[_moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:_moviePlayerController.view];

//_moviePlayerController.fullscreen = YES;
_moviePlayerController.scalingMode = MPMovieScalingModeAspectFill;
_moviePlayerController.view.backgroundColor = [UIColor clearColor];
[_moviePlayerController play];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM