라이브 스트림에 프리롤 광고 로드

플랫폼 선택: HTML5 Android iOS tvOS

IMA SDK는 주문형 동영상뿐만 아니라 실시간 스트림으로도 수익을 창출하는 데 사용할 수 있습니다. 실시간 스트림의 경우 각 광고 시간마다 새 광고 요청을 해야 합니다. 모든 시청자가 동시에 광고를 요청하여 광고 서버가 과부하되지 않도록 이러한 요청을 분산하세요.

이를 지원하기 위해 IMA SDK에는 AdsRequest.liveStreamPrefetchSeconds 속성이 있습니다. 이 속성은 AdsLoader.requestAds()를 호출한 후 SDK가 광고 서버에 연결하기 전에 대기해야 하는 최대 시간(초)을 지정합니다. 실제 요청 시간은 무작위로 지정됩니다. 예를 들어 AdsRequest.liveStreamPrefetchSeconds를 30으로 설정하면 SDK는 AdsLoader.requestAds()를 호출한 후 0~30초 동안 기다린 후 서버에 실제로 요청을 보냅니다.

실제 라이브 스트림 프리페치

광고 시간이 완료되는 즉시 다음 광고 시간을 프리페치하는 것이 좋습니다. 이렇게 하면 프리페치 창에 최대 시간이 확보됩니다. 광고 시간 사이에 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

    ...
  }
}