The IMA SDK can be used to monetize live streams as well as video-on-demand.
For live streams, you need to make a new ad request for each ad break.
Stagger these requests to ensure that all of your viewers aren't requesting
ads at the same time and bogging down the ad server(s).
To help with this, the IMA SDK has the AdsRequest.liveStreamPrefetchSeconds
property. This property specifies the maximum number of seconds the SDK
should wait before reaching out to the ad server after you call
AdsLoader.requestAds(). The actual request time will be randomized. For
example, if you set AdsRequest.liveStreamPrefetchSeconds to 30, the SDK
waits 0 to 30 seconds after you call AdsLoader.requestAds() to actually
make the request to the server.
Live stream pre-fetch in practice
We recommend pre-fetching your next ad break as soon as an ad break completes.
This ensures the maximum length of time is available for your pre-fetch window.
Suppose you have 5 minutes between ad breaks. When an ad break completes,
you can request your next ad break with a pre-fetch window of 290 seconds
(5 minutes minus 10 seconds, to make sure the requests sent at the end of
the pre-fetch window have enough time to resolve):
Objective-C
-(void)adsManager:(IMAAdsManager*)adsManagerdidReceiveAdEvent:(IMAAdEvent*)event{...switch(event.type){...casekIMAAdEvent_ALL_ADS_COMPLETED:IMAAdsRequest*request=[[IMAAdsRequestalloc]initWithAdTagUrl:self.adTagUrladDisplayContainer:self.adDisplayContaineravPlayerVideoDisplay:self.avPlayerVideoDisplaypictureInPictureProxy:self.pictureInPictureProxyuserContext:nil];// set a delay between the end of the last ad// in the last request, and the first ad from// the new requestFloat64adGap=30;// make sure the request occurs at least five// seconds before starting the new set of adsrequest.liveStreamPrefetchSeconds=adGap-5;[self.adsLoaderrequestAdsWithRequest:request];// start new ads after adGap seconds have elapseddispatch_after(dispatch_time(DISPATCH_TIME_NOW,adGap*NSEC_PER_SEC),dispatch_get_main_queue(),^{[adsManagerstart];});break;...}...}
Swift
funcadsManager(_adsManager:IMAAdsManager!,didReceiveevent:IMAAdEvent!){switchevent.type{...caseIMAAdEventType.ALL_ADS_COMPLETED:letrequest=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 requestletadGap=30// make sure the request occurs at least five// seconds before starting the new set of adsrequest.liveStreamPrefetchSeconds=adGap-5adsLoader.requestAds(with:request)// start new ads after adGap seconds have elapsedDispatchQueue.main.asyncAfter(deadline:.now()+adGap){adsManager.start()}break...}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe IMA SDK allows for monetization of both live streams and video-on-demand content through ad integration.\u003c/p\u003e\n"],["\u003cp\u003eFor live streams, stagger ad requests using the \u003ccode\u003eAdsRequest.liveStreamPrefetchSeconds\u003c/code\u003e property to prevent ad server overload.\u003c/p\u003e\n"],["\u003cp\u003eSetting \u003ccode\u003eAdsRequest.liveStreamPrefetchSeconds\u003c/code\u003e introduces a randomized delay (within the specified range) before the SDK requests ads, helping distribute the load.\u003c/p\u003e\n"],["\u003cp\u003eIt's recommended to pre-fetch the next ad break immediately after the current one finishes, maximizing the available pre-fetch window and ensuring smooth transitions.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples demonstrate how to implement live stream ad pre-fetching in Objective-C and Swift, including setting an appropriate pre-fetch window to avoid delays.\u003c/p\u003e\n"]]],[],null,["Select platform: [HTML5](/interactive-media-ads/docs/sdks/html5/client-side/live-stream \"View this page for the HTML5 platform docs.\") [Android](/interactive-media-ads/docs/sdks/android/client-side/live-stream \"View this page for the Android platform docs.\") [iOS](/interactive-media-ads/docs/sdks/ios/client-side/live-stream \"View this page for the iOS platform docs.\") [tvOS](/interactive-media-ads/docs/sdks/tvos/client-side/live-stream \"View this page for the tvOS platform docs.\")\n\n\u003cbr /\u003e\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\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\nObjective-C \n\n\n - (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event {\n\n ...\n\n switch (event.type) {\n\n ...\n\n case kIMAAdEvent_ALL_ADS_COMPLETED:\n\n IMAAdsRequest *request = [[IMAAdsRequest alloc]\n initWithAdTagUrl: self.adTagUrl\n adDisplayContainer: self.adDisplayContainer\n avPlayerVideoDisplay: self.avPlayerVideoDisplay\n pictureInPictureProxy: self.pictureInPictureProxy\n userContext: nil];\n\n // set a delay between the end of the last ad\n // in the last request, and the first ad from\n // the new request\n Float64 adGap = 30;\n // make sure the request occurs at least five\n // seconds before starting the new set of ads\n request.liveStreamPrefetchSeconds = adGap - 5;\n [self.adsLoader requestAdsWithRequest:request];\n // start new ads after adGap seconds have elapsed\n dispatch_after(dispatch_time(DISPATCH_TIME_NOW, adGap * NSEC_PER_SEC), dispatch_get_main_queue(), ^{\n [adsManager start];\n });\n\n break;\n\n ...\n\n }\n\n ...\n\n }\n\nSwift \n\n func adsManager(_ adsManager: IMAAdsManager!, didReceive event: IMAAdEvent!) {\n switch event.type {\n\n ...\n\n case IMAAdEventType.ALL_ADS_COMPLETED:\n\n let request = IMAAdsRequest(\n adTagUrl: AdTagUrl,\n adDisplayContainer: adDisplayContainer,\n contentPlayhead: contentPlayhead,\n userContext: nil)\n\n // set a delay between the end of the last ad\n // in the last request, and the first ad from\n // the new request\n let adGap = 30\n // make sure the request occurs at least five\n // seconds before starting the new set of ads\n request.liveStreamPrefetchSeconds = adGap - 5\n adsLoader.requestAds(with: request)\n // start new ads after adGap seconds have elapsed\n DispatchQueue.main.asyncAfter(deadline: .now() + adGap) {\n adsManager.start()\n }\n\n break\n\n ...\n }\n }"]]