שליפה מראש של שידור חי

ניתן להשתמש ב-IMA SDK לייצור הכנסות משידורים חיים ומצפייה בווידאו על פי דרישה. בשידורים חיים, צריך לשלוח בקשה חדשה להצגת מודעה עבור כל הפסקה למודעות. הגדירו את הבקשות האלה כדי להבטיח שכל הצופים לא יבקשו מודעות בו-זמנית, ותעכבו את שרתי המודעות.

כדי לעזור בכך, ל-IMA SDK יש את המאפיין AdsRequest.liveStreamPrefetchSeconds. המאפיין הזה מציין את מספר השניות המקסימלי שעל ה-SDK להמתין לפני יצירת קשר עם שרת המודעות אחרי ביצוע קריאה ל-AdsLoader.requestAds(). זמן הבקשה בפועל יהיה אקראי. לדוגמה, אם מגדירים את הערך AdsRequest.liveStreamPrefetchSeconds ל-30, ה-SDK ימתין 0 עד 30 שניות אחרי הקריאה ל-AdsLoader.requestAds() כדי לשלוח את הבקשה לשרת בפועל.

שליפה מראש של שידורים חיים – בפועל

מומלץ לבצע מראש את העיבוד של ההפסקה הבאה למודעות מיד לאחר שההפסקה למודעה מסתיימת. כך ניתן להבטיח שמשך הזמן המרבי יהיה זמין לחלון השליפה מראש (prefetch). נניח שיש 5 דקות בין הפסקות למודעות. בסיום ההפסקה למודעה, תוכלו לבקש את ההפסקה הבאה למודעות עם חלון של 290 שניות לשליפה מראש (5 דקות פחות 10 שניות, כדי לוודא שלבקשות שנשלחות בסוף החלון לשליפה מראש יהיה מספיק זמן לפתור):

Objective-C


- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event {

  ...

  switch (event.type) {

    ...

    case kIMAAdEvent_ALL_ADS_COMPLETED:

      IMAAdsRequest *request = [[IMAAdsRequest alloc]
             initWithAdTagUrl: self.adTagUrl
           adDisplayContainer: self.adDisplayContainer
         avPlayerVideoDisplay: self.avPlayerVideoDisplay
        pictureInPictureProxy: self.pictureInPictureProxy
                  userContext: nil];

      // set a delay between the end of the last ad
      // in the last request, and the first ad from
      // the new request
      Float64 adGap = 30;
      // make sure the request occurs at least five
      // seconds before starting the new set of ads
      request.liveStreamPrefetchSeconds = adGap - 5;
      [self.adsLoader requestAdsWithRequest:request];
      // start new ads after adGap seconds have elapsed
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, adGap * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [adsManager start];
      });

      break;

    ...

  }

  ...

}

Swift

func adsManager(_ adsManager: IMAAdsManager!, didReceive event: IMAAdEvent!) {
  switch event.type {

    ...

    case IMAAdEventType.ALL_ADS_COMPLETED:

      let request = IMAAdsRequest(
        adTagUrl: AdTagUrl,
        adDisplayContainer: adDisplayContainer,
        contentPlayhead: contentPlayhead,
        userContext: nil)

      // set a delay between the end of the last ad
      // in the last request, and the first ad from
      // the new request
      let adGap = 30
      // make sure the request occurs at least five
      // seconds before starting the new set of ads
      request.liveStreamPrefetchSeconds = adGap - 5
      adsLoader.requestAds(with: request)
      // start new ads after adGap seconds have elapsed
      DispatchQueue.main.asyncAfter(deadline: .now() + adGap) {
        adsManager.start()
      }

      break

    ...
  }
}