लाइव स्ट्रीम के लिए, वीडियो शुरू होने से पहले दिखने वाले विज्ञापन लोड करना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
IMA SDK का इस्तेमाल, लाइव स्ट्रीम के साथ-साथ 'मांग पर वीडियो' से कमाई करने के लिए भी किया जा सकता है.
लाइव स्ट्रीम के लिए, आपको विज्ञापन के लिए हर ब्रेक के लिए एक नया विज्ञापन अनुरोध करना होगा.
यह पक्का करने के लिए कि आपके सभी दर्शक अनुरोध न कर रहे हों, इन अनुरोधों को एक साथ लगाएं
विज्ञापन सर्वर को ट्रैक नहीं करता है.
इसमें मदद करने के लिए, IMA SDK के पास AdsRequest.liveStreamPrefetchSeconds
प्रॉपर्टी. इस प्रॉपर्टी से पता चलता है कि एसडीके ज़्यादा से ज़्यादा कितने सेकंड तक इस्तेमाल कर सकता है
आपके कॉल करने के बाद विज्ञापन सर्वर से संपर्क करने से पहले आपको इंतज़ार करना होगा
AdsLoader.requestAds()
. अनुरोध करने के समय को बिना किसी क्रम के चुना जाएगा. इसके लिए
उदाहरण के लिए, अगर AdsRequest.liveStreamPrefetchSeconds
को 30 पर सेट किया जाता है, तो SDK टूल
AdsLoader.requestAds()
को कॉल करने के बाद, 0 से 30 सेकंड तक इंतज़ार करेगा
सर्वर से अनुरोध करेगा.
लाइव स्ट्रीम प्री-फ़ेच की सुविधा
हमारा सुझाव है कि विज्ञापन के लिए ब्रेक पूरा होते ही, अगला विज्ञापन ब्रेक पहले से फ़ेच करें.
इससे यह पक्का होता है कि प्री-फ़ेच विंडो के लिए, ज़्यादा से ज़्यादा समयसीमा उपलब्ध है.
मान लीजिए कि विज्ञापन के लिए ब्रेक के बीच का समय 5 मिनट है. विज्ञापन के लिए ब्रेक पूरा होने पर,
विज्ञापन के लिए 290 सेकंड की प्री-फ़ेच विंडो के साथ, अगले विज्ञापन के लिए ब्रेक का अनुरोध किया जा सकता है
(यह पक्का करने के लिए कि अनुरोध के आखिर में भेजे गए अनुरोध, 5 मिनट में से 10 सेकंड में से छूट जाएं
प्री-फ़ेच विंडो में, समाधान करने के लिए काफ़ी समय होता है):
Objective-C
- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event {
...
switch (event.type) {
...
case kIMAAdEvent_ALL_ADS_COMPLETED:
IMAAdsRequest *request = [[IMAAdsRequest alloc]
initWithAdTagUrl: self.adTagUrl
adDisplayContainer: self.adDisplayContainer
avPlayerVideoDisplay: self.avPlayerVideoDisplay
pictureInPictureProxy: self.pictureInPictureProxy
userContext: nil];
// set a delay between the end of the last ad
// in the last request, and the first ad from
// the new request
Float64 adGap = 30;
// make sure the request occurs at least five
// seconds before starting the new set of ads
request.liveStreamPrefetchSeconds = adGap - 5;
[self.adsLoader requestAdsWithRequest:request];
// start new ads after adGap seconds have elapsed
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, adGap * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[adsManager start];
});
break;
...
}
...
}
Swift
func adsManager(_ adsManager: IMAAdsManager!, didReceive event: IMAAdEvent!) {
switch event.type {
...
case IMAAdEventType.ALL_ADS_COMPLETED:
let request = 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 request
let adGap = 30
// make sure the request occurs at least five
// seconds before starting the new set of ads
request.liveStreamPrefetchSeconds = adGap - 5
adsLoader.requestAds(with: request)
// start new ads after adGap seconds have elapsed
DispatchQueue.main.asyncAfter(deadline: .now() + adGap) {
adsManager.start()
}
break
...
}
}
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-01 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-08-01 (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 pre-fetch window and ensuring smoother transitions.\u003c/p\u003e\n"],["\u003cp\u003eExample code snippets (Objective-C and Swift) demonstrate how to implement live stream pre-fetching and manage ad breaks effectively.\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\n### Objective-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\n### Swift\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 }"]]