IMA SDK は、ライブ ストリームとビデオ オンデマンドの収益化に使用できます。 ライブ配信では、ミッドロール挿入点ごとに新しい広告リクエストを送信する必要があります。 すべての視聴者がリクエストしていないよう、リクエストを段階的に実施します。 複数の広告が同時に存在し、広告サーバーの動きが遅くなっていました。
これに対応するため、IMA SDK には AdsRequest.liveStreamPrefetchSeconds
プロパティです。このプロパティは、SDK の最大秒数を指定します
呼び出し後、広告サーバーにアクセスできるようになるまで、待機する必要があります。
AdsLoader.requestAds()
。実際のリクエスト時間はランダムです。対象
たとえば、AdsRequest.liveStreamPrefetchSeconds
を 30 に設定すると、SDK は
AdsLoader.requestAds()
を呼び出してから 0 ~ 30 秒待ってから、
サーバーにリクエストを送信する必要があります。
ライブ配信のプリフェッチの実例
ミッドロール挿入点が完了したら、すぐに次のミッドロール挿入点をプリフェッチすることをおすすめします。 これにより、プリフェッチ ウィンドウに使用可能な最大時間が確保されます。 ミッドロール挿入点の間隔が 5 分だとします。ミッドロール挿入点が完了すると 290 秒のプリフェッチウィンドウで次のミッドロール挿入点をリクエストできます。 (5 分から 10 秒を引いて、セッションの最後に送信されたリクエストが プリフェッチ ウィンドウが解決するのに十分な時間がある):
次のコード スニペットは、ライブ配信のプリフェッチを 高度な例 をご覧ください。この方法は他の IMA 実装にも適用できます。
VideoPlayerController.java
/** Ads logic for handling the IMA SDK integration code and events. */
public class VideoPlayerController {
// 5 minutes == 300 seconds. Include a 10 second buffer
private float AD_INTERVAL = 290;
private double AD_TIMEOUT = 300;
...
adsManager.addAdEventListener(
new AdEvent.AdEventListener() {
/** Responds to AdEvents. */
@Override
public void onAdEvent(AdEvent adEvent) {
...
case ALL_ADS_COMPLETED:
if (adsManager != null) {
adsManager.destroy();
adsManager = null;
}
// When pre-fetching for live streams, be sure to destroy the current AdsManager,
// in case the tag you requested previously contains post-rolls
// (you don't want to play those now).
// Pre-fetch the next ad break.
// Play those ads in ~5 minutes. In a real-world implementation,
// this will likely be done as the result of a message from your
// streaming server, not a via the playAdsAfterThisTime parameter
// of requestAndPlayAds().
requestAndPlayAds(AD_TIMEOUT);
break;
default:
break;
}
}
...
public void requestAndPlayAds(double playAdsAfterThisTime) {
if (currentAdTagUrl == null || currentAdTagUrl == "") {
log("No VAST ad tag URL specified");
resumeContent();
return;
}
// Since you're switching to a new video, tell the SDK the previous video is finished.
if (adsManager != null) {
adsManager.destroy();
}
playButton.setVisibility(View.GONE);
// Create the ads request.
AdsRequest request = sdkFactory.createAdsRequest();
request.setAdTagUrl(currentAdTagUrl);
request.setContentProgressProvider(videoPlayerWithAdPlayback.getContentProgressProvider());
request.setLiveStreamPrefetchSeconds(AD_INTERVAL);
playAdsAfterTime = playAdsAfterThisTime;
// Request the ad. After the ad is loaded, onAdsManagerLoaded() will be called.
adsLoader.requestAds(request);
}