الجلب المسبق للبث المباشر

يمكن استخدام حزمة تطوير البرامج لإعلانات الوسائط التفاعلية لتحقيق ربح من أحداث البث المباشر والفيديوهات عند الطلب. بالنسبة إلى أحداث البث المباشر، عليك تقديم طلب إعلان جديد لكل فاصل إعلاني. يمكنك ترتيب هذه الطلبات للتأكّد من أنّ جميع المشاهدين لا يطلبون الإعلانات في الوقت نفسه وأنّهم يعيقون أداء خوادم الإعلانات.

للمساعدة في ذلك، تحتوي حزمة تطوير البرامج لإعلانات الوسائط التفاعلية على السمة AdsRequest.liveStreamPrefetchSeconds. تحدّد هذه السمة الحد الأقصى لعدد الثواني التي يجب أن تنتظرها حزمة SDK قبل الوصول إلى خادم الإعلانات بعد طلب البيانات AdsLoader.requestAds(). سيتم توزيع وقت الطلب الفعلي عشوائيًا. على سبيل المثال، في حال ضبط AdsRequest.liveStreamPrefetchSeconds على 30، تنتظر حزمة SDK مدة تتراوح بين 0 و30 ثانية بعد استدعاء AdsLoader.requestAds() لإرسال الطلب إلى الخادم.

التطبيق العملي على الجلب المُسبَق للبث المباشر

ننصحك بجلب الفاصل الإعلاني التالي مسبقًا فور اكتماله. يضمن ذلك الحدّ الأقصى لطول مدة نافذة الجلب المسبق. لنفرض أنّ هناك 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

    ...
  }
}