【问题标题】:How to use IMA SDK to play pre-roll video ads with MPMoviePlayerController in swift如何使用 IMA SDK 在 swift 中使用 MPMoviePlayerController 播放前贴片视频广告
【发布时间】:2015-02-19 13:00:57
【问题描述】:
我正在使用 Swift 语言在 iOS 应用程序中工作。我需要在我的应用程序中实现谷歌前贴片视频广告,并且我正在使用 MPMoviePlayerController 播放视频。所以我可以使用 MPMoviePlayerController 播放 DFP 前贴片视频广告。如何使用 MPMoviePlayerController 快速实现 IMA SDK。
请提供一些示例和任何其他选项以使用Out IMA SDK 播放 DFP 前贴片广告视频
谢谢
【问题讨论】:
标签:
ios
iphone
swift
ios7
ios8.1
【解决方案1】:
NSURL *fileURL = [NSURL URLWithString:urlplay];
moviePlayerController=[[MPMoviePlayerController alloc]initWithContentURL:fileURL];
[NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updatePlaybackProgressFromTimer:)
userInfo:nil
repeats:YES];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.delegate = self;
tap.numberOfTapsRequired = 1;
[moviePlayerController.view addGestureRecognizer:tap];
moviePlayerController.movieSourceType = MPMovieSourceTypeStreaming;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Exit:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playstart:) name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Statechange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(LoadFinish:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[moviePlayerController setFullscreen:YES animated:YES];
moviePlayerController.view.frame = CGRectMake(0,568, [AppDelegate sharedInstance].widht, [AppDelegate sharedInstance].height);
[self.navigationController setNavigationBarHidden:YES];
[UIView animateWithDuration:0.7
delay:0.5
options: UIViewAnimationCurveEaseOut
animations:^{
[moviePlayerController.view setFrame:CGRectMake(0,0,[AppDelegate sharedInstance].widht, [AppDelegate sharedInstance].height)];
}
completion:^(BOOL finished)
{
}];
moviePlayerController.controlStyle=MPMovieControlStyleFullscreen;
moviePlayerController.backgroundView.hidden = YES;
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];