I have a problem with MPMoviePlayerController [iPhone SDK]

I want to create an application with an intro video, like gameloft games. so when the application works, the movie plays perfectly, but before it plays ... my first xib file of the FirstViewController file will start playing first! What for? here is my code:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"movie" ofType:@"m4v"];

    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];

    MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    IntroMovie.movieControlMode = MPMovieControlModeHidden;
    [IntroMovie play];
}
+3
source share
2 answers

An alternative is to add another view (for example, a simple black background), and then replace it after the video has finished playing:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"Hafez-2" ofType:@"mov"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];


    MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [IntroMovie setOrientation:UIDeviceOrientationPortrait animated:NO];
    [IntroMovie play];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlaybackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil]; 
    // Create an initial pure black view
    UIView* blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    blackView.backgroundColor = [UIColor blackColor];
    [window addSubview:blackView]; // sends [blackView retain]
    [blackView release];
    [window makeKeyAndVisible];
}

- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
    UIView* blackView = [[window subviews] objectAtIndex:0];
    [blackView removeFromSuperview]; // sends [blackView release]
    [window addSubview:viewController.view];
}

Let me know if you need a modified source from your example and I can send it somewhere

+3
source

, , .

. :

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"Hafez-2" ofType:@"mov"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];


    MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [IntroMovie setOrientation:UIDeviceOrientationPortrait animated:NO];
    [IntroMovie play];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlaybackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil]; 
}

- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}
+6

Source: https://habr.com/ru/post/1728326/


All Articles