Resolved trying to play video with MPMoviePlayerController just gives me black screen

Discussion in 'iOS Programming' started by straber, Mar 9, 2013.

  1. straber, Mar 9, 2013
    Last edited: Mar 17, 2013

    straber macrumors member

    Jul 3, 2012
    I'm trying to use a MPMoviePlayerController to play a movie, but all I get is a black screen. Any ideas why this is? Here's the code I'm using.

    - (void)playVideo:(ChatMessage *)msg {
        NSURL *movieURL = msg.videoURL;
        self.player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
        [self.player prepareToPlay];
        [self.player.view setFrame: self.view.bounds];  
        [self.player play];
    Thanks for any help...
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    How are you presenting your movie player's view? Have you confirmed that you have a valid URL? Have you done any other debugging? If so, what?
  3. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia
    You are missing a key part. You create a movie player controller, but never add it's view to your view.

    you meed a line like this:

    [self.view addSubView self.player.view];
    Otherwise the movie player's view will not be displayed anywhere.
  4. straber thread starter macrumors member

    Jul 3, 2012
    Thanks for your help,

    that's exactly what I was missing, I mistakenly forgot to add the players view as a subview.

    [self.view addSubview:self.player.view];
    fixed the problem.

    I can't believe I didn't catch that. Damn, it's been a long week. Lol.

Share This Page