繁体   English   中英

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

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

刚刚将项目从iOS5升级到了iOS7。 由于某种原因,我无法理解视频现在可以在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");
}

视图根据日志加载两次

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

视频文件是本地的。

MPMoviePlayerPlaybackDidFinishNotification正在触发,但不是执行segue,而是重新加载了视图控制器,并且只有segue才第二次调用MPMoviePlayerPlaybackDidFinishNotification时才唤醒。

如果这有什么区别,那就是自定义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];
    }
}

事实是,这并不是每个iOS7都发生的

罪魁祸首似乎是_moviePlayerController.fullscreen = YES;

我用[_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