تبلیغات پیش از پخش را برای پخش زنده بارگیری کنید

Google Media Interactive Ads SDK (IMA) برای iOS.

از IMA SDK می‌توان برای کسب درآمد از جریان‌های زنده و همچنین ویدیوهای درخواستی استفاده کرد. برای پخش جریانی زنده، باید برای هر وقفه تبلیغاتی یک درخواست آگهی جدید ارائه دهید. این درخواست‌ها را تکان دهید تا مطمئن شوید که همه بینندگان شما به طور هم‌زمان درخواست تبلیغات نمی‌کنند و سرور(های) تبلیغات را دچار مشکل نمی‌کنند.

برای کمک به این امر، IMA SDK دارای ویژگی AdsRequest.liveStreamPrefetchSeconds است. این ویژگی حداکثر ثانیه‌ای را مشخص می‌کند که SDK باید قبل از تماس با سرور آگهی پس از فراخوانی AdsLoader.requestAds() منتظر بماند. زمان واقعی درخواست تصادفی خواهد شد. به عنوان مثال، اگر AdsRequest.liveStreamPrefetchSeconds روی 30 تنظیم کنید، SDK پس از فراخوانی AdsLoader.requestAds() بین 0 تا 30 ثانیه منتظر می ماند تا در واقع درخواست را به سرور ارسال کند.

پخش زنده از پیش واکشی در عمل

توصیه می کنیم به محض اتمام وقفه آگهی، وقفه آگهی بعدی خود را از قبل واکشی کنید. این تضمین می کند که حداکثر مدت زمان برای پنجره پیش واکشی شما در دسترس است. فرض کنید بین وقفه های تبلیغاتی 5 دقیقه فرصت دارید. هنگامی که یک وقفه تبلیغاتی کامل شد، می‌توانید وقفه آگهی بعدی خود را با یک پنجره پیش واکشی 290 ثانیه‌ای (5 دقیقه منهای 10 ثانیه) درخواست کنید تا مطمئن شوید درخواست‌های ارسال شده در انتهای پنجره پیش واکشی زمان کافی برای حل کردن دارند:

هدف-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;

    ...

  }

  ...

}

سویفت

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

    ...
  }
}