playPrerollAd WithCompletionHandler问题

时间:2014-01-16 15:55:39

标签: ios iphone mpmovieplayercontroller iad

我配置MPMoviewPlayerController以在播放视频之前显示iAd。所以基本上我的代码看起来像这样

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];

在AppDelegate中

[MPMoviePlayerController preparePrerollAds];

但问题是我收到了声音,但播放器没有显示视频。此外,我在完成处理程序中没有任何错误...非常感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题(我可以听到音频,但没有播放视频),我得到了response on the Apple Developer Forums

看来你必须确保只有一个对电影播放器​​控制器的引用。这是我使用的代码,现在可以使用:

@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];
}


然后,我使用:

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


我希望有所帮助。

答案 1 :(得分:0)

对我而言,只有当播放器设置为全屏时才有效。

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