Question

I configure a MPMoviewPlayerController to display iAd before I play a video. So basicaly my code looks like this

player = [MPMoviePlayerController new];
player.contentURL = videoURL;    
[player playPrerollAdWithCompletionHandler:^(NSError *error) {
    NSLog(@"error playing ad %@", error.userInfo);
    [player play];
}];

[self.contentView addSubview:player.view];
[self.contentView layoutIfNeeded];

And in AppDelegate

[MPMoviePlayerController preparePrerollAds];

But the problem is that i receive the sound, but player does not display a video. Also I don't get any error in completion handler… Any help is very appreciated!

Was it helpful?

Solution

For me it only works when the player is set to fullscreen.

[parent.view addSubview: player.view];
[parent.view bringSubviewToFront:player.view];
[player setFullscreen:YES animated:YES];

OTHER TIPS

I was having the same problem (I could hear the audio, but no video played), and I got a response on the Apple Developer Forums.

It appears you have to make sure there's only one reference to the movie player controller. This is the code I used, which now works:

@interface UIViewController ()

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

@end


MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.contentURL = movieURL;

if (moviePlayer)
{
    self.moviePlayer = moviePlayer;
    moviePlayer = nil;

    [self.moviePlayer prepareToPlay];
    [self.view addSubview:self.moviePlayer.view];
}


Then later, I use:

- (void)playVideo
{
    [self.moviePlayer playPrerollAdWithCompletionHandler:^(NSError *error) {
        if (!error)
        {
            [self.moviePlayer play];
        }
    }];
}


I hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top