gpt4 book ai didi

ios - 使用playPrerollAdWithCompletionHandler方法通过MPMoviePlayerController实现iAd视频

转载 作者:行者123 更新时间:2023-12-01 16:30:49 29 4
gpt4 key购买 nike

好吧,我想在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”视频,但未展示任何广告。

最佳答案

在调用prepareToPlay之前,您需要先对MPMoviePlayerController进行playPrerollAdWithCompletionHandler编码,然后在对MPMoviePlayerController进行编码之前,将view添加到play中。另外,您可能在[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];
}];
}

关于ios - 使用playPrerollAdWithCompletionHandler方法通过MPMoviePlayerController实现iAd视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31785731/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com