Scheduled Video Ads
Implementing View Controller
In the view controller that will present the ad view as subview,
-
add these properties
GFPVideoAdScheduleManager *scheduleManager
IBOutlet UIView *videoView
AVPlayer *contentPlayer
-
and implement this delegate protocol
GFPVideoAdScheduleManagerDelegate
- Objective-C
- Swift
// MyViewController.h
@import GFPSDK;
@interface MyViewController : UIViewController <GFPVideoAdScheduleManagerDelegate>
@property (nonatomic) GFPVideoAdScheduleManager *scheduleManager;
@property (nonatomic) IBOutlet UIView *videoView;
@property (nonatomic) AVPlayer *contentPlayer;
@end
// MyViewController.h
import GFPSDK
class MyViewController : UIViewController, GFPVideoAdScheduleManagerDelegate {
var scheduleManager : GFPVideoAdScheduleManager?
@IBOutlet var videoView : UIView!
var contentPlayer : AVPlayer?
}
GFPVideoAdScheduleManager
Initialize GFPVideoAdScheduleManager
in your view controller, say, in viewDidLoad:
and request an ad.
-
Provide
GFPVideoAdScheduleManager
with video ad Schedule ID (essential) as registered on GFP dashboard, an AVPlayer instance, UIView to enclose video view, andGFPAdScheduleParam
(optional) for better ad performance. -
Set
GFPVideoAdScheduleManagerDelegate
(required) toGFPVideoAdScheduleManager
GFPVideoAdScheduleManager must be manually deallocated by calling destroy:
method.
- Objective-C
- Swift
- (void)viewDidLoad {
[super viewDidLoad];
GFPAdParam *adParam = [[GFPAdParam alloc]init];
adParam.yearOfBirth = 1990;
adParam.gender = GFPAdParamGenderTypeMale;
...
GFPVideoPlacementType type = GFPVideoPlacementTypePre | GFPVideoPlacementTypeMid | GFPVideoPlacementTypePost;
GFPAdScheduleParam *param = [[GFPAdScheduleParam alloc] initWithPlacementPolicy: type duration: CMTimeGetSeconds(Content duration) param: adParam];
param.noticeDurationSec = 5.0;
...
self.scheduleManager = [[GFPVideoAdScheduleManager alloc] initWithAdScheduleID: @"YOUR_SCHEDULE_ID"
contentPlayer: contentPlayer
videoView: videoView
scheduleParam: param];
self.scheduleManager.renderingSetting = [GFPVideoAdRenderingSetting alloc] init];
self.scheduleManager.delegate = self;
self.scheduleManager.qoeDelegate = self;
[self.scheduleManager loadSchedule];
}
override func viewDidLoad() {
super.viewDidLoad()
let adParam = GFPAdParam()
adParam.yearOfBirth = 1990
adParam.gender = .male
...
let scheduleParam = GFPAdScheduleParam(placementPolicy: .full, duration: CMTimeGetSeconds(self.duration!), param: adParam)
scheduleParam.noticeDurationSec = 5.0
self.scheduleManager = GFPVideoAdScheduleManager(adScheduleID: "YOUR_SCHEDULE_ID", contentPlayer: contentPlayer, videoView: videoView, scheduleParam: scheduleParam)
self.scheduleManager?.renderingSetting = GFPVideoAdRenderingSetting()
self.scheduleManager?.delegate = self
self.scheduleManager?.qoeDelegate = self
self.scheduleManager?.loadSchedule()
}
Additional Configurations
Preliminary Ad Notice Duration
Video ad notice label refers to text label such as "Plays Ad in 5 Seconds", in advance of start playing ad video.
Set duration by GFPAdScheduleParam.noticeDurationSec
- Objective-C
- Swift
scheduleParam.noticeDurationSec = 5.0;
scheduleParam.noticeDurationSec = 5.0
GFPVideoAdScheduleManagerDelegate
Schedule Events
On Schedule Request Success
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager didLoadedSchedule:(NSArray <GFPVideoAdBreak *> * _Nullable)aAdBreak {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didLoadedSchedule aAdBreak: [GFPVideoAdBreak]?) {
...
}
On Schedule Request Failure
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager didFailScheduleWithError:(GFPError *)aError {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didFailScheduleWithError aError: GFPError) {
...
}
On Schedule Complete
- Objective-C
- Swift
- (void)scheduleManagerDidCompleted:(GFPVideoAdScheduleManager *)aScheduleAdManager {
...
}
func scheduleManagerDidCompleted(_ aScheduleAdManager: GFPVideoAdScheduleManager) {
...
}
Video Playback Events
On Resuming Content
Called when the player resumes, in other words, continues to play content video in case of ad schedule failure or ad video fails to play
- Objective-C
- Swift
- (void)scheduleManagerContentResumeRequest:(GFPVideoAdScheduleManager *)aScheduleAdManager {
...
}
func scheduleManagerContentResumeRequest(_ aScheduleAdManager: GFPVideoAdScheduleManager) {
...
}
On Pausing Content
Called when the player pauses content to play ad video.
- Objective-C
- Swift
- (void)scheduleManagerContentPauseRequest:(GFPVideoAdScheduleManager *)aScheduleAdManager {
...
}
func scheduleManagerContentPauseRequest(_ aScheduleAdManager: GFPVideoAdScheduleManager) {
...
}
Video Ad Events
See more information in GFPVideoAdScheduleManagerDelegate.h
On Ad Failure
Ad failure includes ad load and ad video playback failure.
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager didFailWithResult:(GFPVideoAdBreakResult *)aResult {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didFailWith aResult: GFPVideoAdBreakResult) {
...
}
On Ad Loaded
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager didLoadAd:(GFPVideoAdBreakResult *)aResult {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didLoadAd aResult: GFPVideoAdBreakResult) {
...
}
On Ad Video Started
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager didStartAd:(GFPVideoAdBreakResult *)aResult {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didStartAd aResult: GFPVideoAdBreakResult) {
...
}
On Ad Video Ready
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager didStartReadyAd:(GFPVideoAdBreakResult *)aResult {
/* 1. Manually hide preliminary ad notice label */
/* 2. Manually stop content video player. */
...
[self.scheduleAdManager startWith: NO or YES]; /* 3. Start ad video */
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didStartReadyAd aResult: GFPVideoAdBreakResult) {
/* 1. Manually hide preliminary ad notice label */
/* 2. Manually stop content video player. */
...
self.scheduleAdManager?.start(with: true) /* 3. Start ad video */
}
On Video Ad Playback Ended
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager didCompleteAd:(GFPVideoAdBreakResult *)aResult {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didCompleteAd aResult: GFPVideoAdBreakResult) {
...
}
On Show Preliminary Ad Notice Label
GFPAdScheduleParam.noticeDurationSec
must be set to call this delegate method.
SDK only notifies the time to show the notice label through this method. It is app's will to manually render the notice label view.
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager showAdNotice:(NSInteger)aDuration {
/* Show to notice label */
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, showAdNotice aDuration: Int) {
/* Show to notice label */
...
}
On Clicked
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager wasClicked:(GFPVideoAdBreakResult *)aResult {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, wasClicked aResult: GFPVideoAdBreakResult) {
...
}
AVPlayer Log Event
It is called only if video player is configured as AVPlayer.
- Objective-C
- Swift
- (void)scheduleManager:(GFPVideoAdScheduleManager *)aScheduleAdManager
didReceiveAccessLogEvents:(NSArray<AVPlayerItemAccessLogEvent *> *)accessLogEvents {
...
}
func scheduleManager(_ aScheduleAdManager: GFPVideoAdScheduleManager, didReceive accessLogEvents: [AVPlayerItemAccessLogEvent]) {
...
}