ライブ配信のプリフェッチ

IMA SDK は、ライブ ストリームとビデオ オンデマンドの収益化に使用できます。 ライブ配信では、ミッドロール挿入点ごとに新しい広告リクエストを送信する必要があります。 すべての視聴者がリクエストしていないよう、リクエストを段階的に実施します。 複数の広告が同時に存在し、広告サーバーの動きが遅くなっていました。

これに対応するため、IMA SDK には AdsRequest.liveStreamPrefetchSeconds プロパティです。このプロパティは、SDK の最大秒数を指定します 呼び出し後、広告サーバーにアクセスできるようになるまで、待機する必要があります。 AdsLoader.requestAds()。実際のリクエスト時間はランダムです。対象 たとえば、AdsRequest.liveStreamPrefetchSeconds を 30 に設定すると、SDK は AdsLoader.requestAds() を呼び出してから 0 ~ 30 秒待ってから、 サーバーにリクエストを送信する必要があります。

ライブ配信のプリフェッチの実例

ミッドロール挿入点が完了したら、すぐに次のミッドロール挿入点をプリフェッチすることをおすすめします。 これにより、プリフェッチ ウィンドウに使用可能な最大時間が確保されます。 ミッドロール挿入点の間隔が 5 分だとします。ミッドロール挿入点が完了すると 290 秒のプリフェッチウィンドウで次のミッドロール挿入点をリクエストできます。 (5 分から 10 秒を引いて、セッションの最後に送信されたリクエストが プリフェッチ ウィンドウが解決するのに十分な時間がある):

// 5 minutes == 300 seconds. Include a 10 second buffer
var AD_INTERVAL = 290;

function onAdEvent(adEvent) {
  var ad = adEvent.getAd();
  switch(adEvent.type) {
    case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:
      // Pre-fetch our next ad break.
      requestAds();
      // Play those ads in 5 minutes. In a real-world implementation,
      // this is likely done as the result of a message from your
      // streaming server, not a timeout.
      setTimeout(playAds, AD_INTERVAL * 1000);// Convert to ms.
  }
}

function requestAds() {
  // Destroy the current AdsManager, in case the tag you requested previously
  // contains post-rolls (don't play those now).
  if (adsManager) {
    adsManager.destroy();
  }
  // Your AdsLoader will be set up on page-load. You should re-use the same
  // AdsLoader for every request. For more info on setting up the AdsLoader,
  // see the "Get Started" guide in the prerequisites above.
  if (adsLoader) {
    // Reset the IMA SDK.
    adsLoader.contentComplete();
  }
  var adsRequest = new google.ima.AdsRequest();
  adsRequest.adTagUrl = '...';
  adsRequest.linearAdSlotWidth = <linear_width>;
  adsRequest.linearAdSlotHeight = <linear_height>;
  adsRequest.nonLinearAdSlotWidth = <nonlinear_width>;
  adsRequest.nonLinearAdSlotHeight = <nonlinear_height>;
  adsRequest.liveStreamPrefechSeconds = AD_INTERVAL;
  adsLoader.requestAds(adsRequest);
}

function playAds() {
  adsManager.init(
      <linear_width>,  <linear_height>, google.ima.ViewMode.NORMAL);
  adsManager.start();
}