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

    Joined:
    Jul 3, 2012
    #1
    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.

    Code:
    - (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

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #3
    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:

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

    Joined:
    Jul 3, 2012
    #4
    Thanks for your help,

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

    Code:
    [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