【问题标题】:implement iAd video with MPMoviePlayerController with playPrerollAdWithCompletionHandler method使用 MPMoviePlayerController 和 playPrerollAdWithCompletionHandler 方法实现 iAd 视频
【发布时间】:2015-08-03 11:11:36
【问题描述】:

嗯,我想在 MPMoviePlayer 中开始播放视频之前展示视频广告

这就是我正在做的:-

    moviePlayer = [MPMoviePlayerController new];

    moviePlayer.contentURL = [NSURL URLWithString:@"http://xyz/xyz.m3u8"];

    [moviePlayer playPrerollAdWithCompletionHandler:^(NSError *error) {
            // Check if error is non-nil during development
            [moviePlayer play];
        }];
    moviePlayer.view.frame=CGRectMake(0, 20, 300, self.view.frame.size.width);
    [self.view addSubview:moviePlayer.view];
    [self.view layoutIfNeeded];

在 Appdelegate.m 中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    [MPMoviePlayerController preparePrerollAds];
    return YES;
}

但我还应该做些什么来展示广告视频或如何配置 iAD 以让应用了解将哪个特定视频作为广告播放。

目前该应用只是播放此网址“http://xyz/xyz.m3u8”的视频,但没有显示任何广告。

【问题讨论】:

    标签: ios objective-c iphone ios7 iad


    【解决方案1】:

    在调用playPrerollAdWithCompletionHandler 之前,您需要先prepareToPlay 您的MPMoviePlayerController,然后在play 之前将您的MPMoviePlayerController 添加到您的view。此外,您可能在[MPMoviePlayerController preparePrerollAds] 有机会完全下载视频广告之前播放视频。检查我的例子:

    #import "ViewController.h"
    @import iAd;
    @import MediaPlayer;
    
    @interface ViewController () {
        MPMoviePlayerController *moviePlayer;
    }
    
    @end
    
    @implementation ViewController
    
    -(void)viewDidLoad {
        [super viewDidLoad];
    
        // Preload ad
        [MPMoviePlayerController preparePrerollAds];
    
        // Create our MPMoviePlayerController
        moviePlayer =[[MPMoviePlayerController alloc]init];
        [moviePlayer.view setFrame: self.view.bounds];
        [moviePlayer setFullscreen:YES animated:YES];
    }
    
    -(IBAction)playButton:(id)sender {
        // Add MPMoviePlayerController to our view
        [self.view addSubview:moviePlayer.view];
    
        // Path of movie you want to play
        NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"someVideo" ofType:@"MOV"];
    
        // Set the contents of our MPMoviePlayerController to our path
        [moviePlayer setContentURL:[NSURL fileURLWithPath:moviePath]];
    
        // Prepare our movie for playback
        [moviePlayer prepareToPlay];
    
        // Play our movie with a prerolled ad
        [moviePlayer playPrerollAdWithCompletionHandler:^(NSError *error) {
            [moviePlayer play];
        }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 2014-02-07
      • 1970-01-01
      相关资源
      最近更新 更多