라이브 스트림에 프리롤 광고 로드
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
IMA SDK는 실시간 스트림 및 VOD로 수익을 창출하는 데 사용할 수 있습니다.
라이브 스트림의 경우 각 광고 시점에 대해 새로운 광고 요청을 해야 합니다.
모든 시청자가 요청하지 않도록 시차를 두고 요청을 보내세요.
광고를 동시에 게재하며 광고 서버를 지연시킬 수 있습니다.
이를 위해 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);
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-01(UTC)
[null,null,["최종 업데이트: 2025-08-01(UTC)"],[[["\u003cp\u003eThe IMA SDK supports monetizing live streams and video-on-demand content through ad integration.\u003c/p\u003e\n"],["\u003cp\u003eFor live streams, stagger ad requests to avoid overloading ad servers by utilizing the \u003ccode\u003eAdsRequest.liveStreamPrefetchSeconds\u003c/code\u003e property for pre-fetching.\u003c/p\u003e\n"],["\u003cp\u003eIt's recommended to pre-fetch the next ad break immediately after the current one finishes, maximizing the pre-fetch window for smoother ad transitions.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets demonstrate how to implement live stream pre-fetching within the Advanced Example, showcasing the integration with the IMA SDK.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAdsRequest.liveStreamPrefetchSeconds\u003c/code\u003e property randomizes the actual request time within the specified maximum duration to further optimize ad delivery.\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\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| **Key Point:** The [Getting started guide](/interactive-media-ads/docs/sdks/android/client-side) and the [Basic Example](//github.com/googleads/googleads-ima-android/tree/main/basicexample) both implement the [Exoplayer-IMA extension](//github.com/google/ExoPlayer/tree/release-v2/extensions/ima) which handles the setup of the AdsManager. Because of this, these resources are not able to be used as a starting point for this guide. We recommend using the [Advanced Example](//github.com/googleads/googleads-ima-android/tree/main/AdvancedExample) as a starting point for live stream pre-fetch.\n\nThese code snippets show how to add live stream pre-fetch to the\n[Advanced Example](//github.com/googleads/googleads-ima-android/tree/main/AdvancedExample)\n, but the approach can applied to other IMA implementations.\n\n**VideoPlayerController.java** \n\n```gdscript\n/** Ads logic for handling the IMA SDK integration code and events. */\npublic class VideoPlayerController {\n\n // 5 minutes == 300 seconds. Include a 10 second buffer\n private float AD_INTERVAL = 290;\n private double AD_TIMEOUT = 300;\n\n...\n\n adsManager.addAdEventListener(\n new AdEvent.AdEventListener() {\n /** Responds to AdEvents. */\n @Override\n public void onAdEvent(AdEvent adEvent) {\n\n ...\n\n case ALL_ADS_COMPLETED:\n if (adsManager != null) {\n adsManager.destroy();\n adsManager = null;\n }\n\n // When pre-fetching for live streams, be sure to destroy the current AdsManager,\n // in case the tag you requested previously contains post-rolls\n // (you don't want to play those now).\n\n // Pre-fetch the next ad break.\n // Play those ads in ~5 minutes. In a real-world implementation,\n // this will likely be done as the result of a message from your\n // streaming server, not a via the playAdsAfterThisTime parameter\n // of requestAndPlayAds().\n requestAndPlayAds(AD_TIMEOUT);\n break;\n default:\n break;\n }\n }\n\n...\n\npublic void requestAndPlayAds(double playAdsAfterThisTime) {\n if (currentAdTagUrl == null || currentAdTagUrl == \"\") {\n log(\"No VAST ad tag URL specified\");\n resumeContent();\n return;\n }\n\n // Since you're switching to a new video, tell the SDK the previous video is finished.\n if (adsManager != null) {\n adsManager.destroy();\n }\n\n playButton.setVisibility(View.GONE);\n\n // Create the ads request.\n AdsRequest request = sdkFactory.createAdsRequest();\n request.setAdTagUrl(currentAdTagUrl);\n request.setContentProgressProvider(videoPlayerWithAdPlayback.getContentProgressProvider());\n request.setLiveStreamPrefetchSeconds(AD_INTERVAL);\n\n playAdsAfterTime = playAdsAfterThisTime;\n\n // Request the ad. After the ad is loaded, onAdsManagerLoaded() will be called.\n adsLoader.requestAds(request);\n}\n```"]]