MPMoviePlayerController gives me a black empty view,no video playing

Pengxuan Li picture Pengxuan Li · May 3, 2012 · Viewed 12.7k times · Source

iOS 5.1 ,here is the code:

 MPMoviePlayerController *player =
    [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:@"map.mp4"]];
    [player prepareToPlay];
    [player.view setFrame: self.view.bounds];  // player's frame must match parent's
    [self.view addSubview: player.view];
    // ...
    [player play];

in fact ,this is just the same as the apple reference say,but when I click the button to use this function,there is just a black Rectangle stay there,no vedio playing ,no sound happening,and no crush,so I want to know how to make this work

Answer

Suresh Varma picture Suresh Varma · Nov 29, 2012

Sorry for very late reply. The Solution is kind of wierd. But it helped me keep going while facing the same issue.

MPMovieSourceTypeStreaming is the thing you have missed.

MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:@"map.mp4"]];
[player prepareToPlay];
[player.view setFrame: self.view.bounds];  // player's frame must match parent's
player.movieSourceType    = MPMovieSourceTypeStreaming;
[self.view addSubview: player.view];
// ...
[player play];