Just upgraded a project from iOS5 to iOS7. For a reason I can not fathom the video now plays twice before the segue works
- (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.
It's custom segue if that makes any difference
#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
The culprit seems to be _moviePlayerController.fullscreen = YES;
I added the screen dimensions instead with [_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];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.