ライブ配信のプレロール広告を読み込む
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
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 IMA HTML5 client-side "Set up the IMA SDK" guide:
// https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/get-started
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>);
adsManager.start();
}
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-01 UTC。
[null,null,["最終更新日 2025-08-01 UTC。"],[[["\u003cp\u003eThe IMA SDK supports monetization for both live streams and video-on-demand content.\u003c/p\u003e\n"],["\u003cp\u003eFor live streams, use the \u003ccode\u003eAdsRequest.liveStreamPrefetchSeconds\u003c/code\u003e property to stagger ad requests and prevent ad server overload.\u003c/p\u003e\n"],["\u003cp\u003ePrefetch the next ad break as soon as the current one completes to maximize the pre-fetch window.\u003c/p\u003e\n"],["\u003cp\u003eImplement a mechanism, such as a timer or server message, to trigger the playback of pre-fetched ads at the desired interval during the live stream.\u003c/p\u003e\n"]]],[],null,["# Load pre-roll ads for livestream\n\nThe IMA SDK can be used to monetize live streams as well as video-on-demand.\nFor live streams, you need to make a new ad request for each ad break.\nStagger these requests to ensure that all of your viewers aren't requesting\nads at the same time and bogging down the ad server(s).\n\nTo help with this, the IMA SDK has the `AdsRequest.liveStreamPrefetchSeconds`\nproperty. This property specifies the maximum number of seconds the SDK\nshould wait before reaching out to the ad server after you call\n`AdsLoader.requestAds()`. The actual request time will be randomized. For\nexample, if you set `AdsRequest.liveStreamPrefetchSeconds` to 30, the SDK\nwaits 0 to 30 seconds after you call `AdsLoader.requestAds()` to actually\nmake the request to the server.\n| **Note:** To see a completed live stream pre-fetch sample, check out our [GitHub sample](//github.com/googleads/googleads-ima-html5/tree/master/live_stream_prefetch).\n\nLive stream pre-fetch in practice\n---------------------------------\n\nWe recommend pre-fetching your next ad break as soon as an ad break completes.\nThis ensures the maximum length of time is available for your pre-fetch window.\nSuppose you have 5 minutes between ad breaks. When an ad break completes,\nyou can request your next ad break with a pre-fetch window of 290 seconds\n(5 minutes minus 10 seconds, to make sure the requests sent at the end of\nthe pre-fetch window have enough time to resolve): \n\n // 5 minutes == 300 seconds. Include a 10 second buffer\n var AD_INTERVAL = 290;\n\n function onAdEvent(adEvent) {\n var ad = adEvent.getAd();\n switch(adEvent.type) {\n case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:\n // Pre-fetch our next ad break.\n requestAds();\n // Play those ads in 5 minutes. In a real-world implementation,\n // this is likely done as the result of a message from your\n // streaming server, not a timeout.\n setTimeout(playAds, AD_INTERVAL * 1000);// Convert to ms.\n }\n }\n\n function requestAds() {\n // Destroy the current AdsManager, in case the tag you requested previously\n // contains post-rolls (don't play those now).\n if (adsManager) {\n adsManager.destroy();\n }\n // Your AdsLoader will be set up on page-load. You should re-use the same\n // AdsLoader for every request. For more info on setting up the AdsLoader,\n // see the IMA HTML5 client-side \"Set up the IMA SDK\" guide:\n // https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/get-started\n if (adsLoader) {\n // Reset the IMA SDK.\n adsLoader.contentComplete();\n }\n var adsRequest = new google.ima.AdsRequest();\n adsRequest.adTagUrl = '...';\n adsRequest.linearAdSlotWidth = \u003clinear_width\u003e;\n adsRequest.linearAdSlotHeight = \u003clinear_height\u003e;\n adsRequest.nonLinearAdSlotWidth = \u003cnonlinear_width\u003e;\n adsRequest.nonLinearAdSlotHeight = \u003cnonlinear_height\u003e;\n adsRequest.liveStreamPrefechSeconds = AD_INTERVAL;\n adsLoader.requestAds(adsRequest);\n }\n\n function playAds() {\n adsManager.init(\u003clinear_width\u003e, \u003clinear_height\u003e);\n adsManager.start();\n }"]]