Mark Reid
Mark Reid

Reputation: 2641

MPMoviePlayerController shows only a black screen

I'm attempting to have a video play directly after the launch screen shows however all I see if a black screen with the status bar showing at the top. At the moment this is all the app does so there's nothing else going on as far as I know that should stop the video playing.

The video plays on the iPad with no problems otherwise, seems to be in the correct format and so on. I'm targeting iOS 7 and I've tried using a different video and also tried using MPMoviePlayerViewController instead. All end up with the same result.

Here's the code I'm using.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSURL *movieURL = [[NSBundle mainBundle] URLForResource:@"IntroMovie" withExtension:@"mov"];

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

    [moviePlayer prepareToPlay];

    [self.window addSubview:moviePlayer.view];

    [moviePlayer play];

    return YES;
}

Upvotes: 0

Views: 4279

Answers (2)

vin
vin

Reputation: 1258

You need to create MPMoviePlayerViewController object and not the former one.The playMovie method should be called after makeKeyAndVisible.If it still doesnt work try adding breakpoints and check if the URL for the given video is correct or not and if it has been added to the Copy Bundle resources.Hope this helps

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
        [self playMovie];
    return YES;
}


-(void)playMovie
{
    NSURL *movieURL;
    NSBundle *bundle = [NSBundle mainBundle];
    if(bundle != nil)
    {
        NSString *moviePath = [bundle pathForResource:@"intro" ofType:@"m4v"];
        if (moviePath)
        {
            movieURL = [NSURL fileURLWithPath:moviePath];

        }
    }


    moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
    moviePlayer.moviePlayer.scalingMode = MPMovieScalingModeFill;
    [self.viewController presentViewController:moviePlayer animated:NO completion:^{

    }];
    [moviePlayer.moviePlayer play];




}

Upvotes: 1

Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19802

Assuming you have no typos and correct project settings the only problem you might have is inside a codec that was used to create "mov" file. Try with some other mov files or try putting your mov file into phone library and try playing it from there

Upvotes: 0

Related Questions