簡體   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