IMA SDK का इस्तेमाल, लाइव स्ट्रीम के साथ-साथ वीडियो-ऑन-डिमांड से कमाई करने के लिए भी किया जा सकता है. लाइव स्ट्रीम के लिए, आपको हर विज्ञापन ब्रेक के लिए एक नया विज्ञापन अनुरोध करना होगा. इन अनुरोधों को इस तरह से मैनेज करें कि सभी दर्शक एक ही समय पर विज्ञापनों का अनुरोध न करें. इससे विज्ञापन सर्वर पर ज़्यादा लोड नहीं पड़ेगा.
इसके लिए, IMA SDK में AdsRequest.liveStreamPrefetchSeconds
प्रॉपर्टी मौजूद है. यह प्रॉपर्टी, ज़्यादा से ज़्यादा उन सेकंड की संख्या के बारे में बताती है जितने सेकंड तक SDK को विज्ञापन सर्वर से संपर्क करने से पहले इंतज़ार करना चाहिए. ऐसा तब होता है, जब आपने AdsLoader.requestAds()
को कॉल किया हो. अनुरोध करने का असल समय, रैंडम होगा. उदाहरण के लिए, अगर आपने AdsRequest.liveStreamPrefetchSeconds
को 30 पर सेट किया है, तो SDK टूल, सर्वर को अनुरोध भेजने के लिए AdsLoader.requestAds()
को कॉल करने के बाद, 0 से 30 सेकंड तक इंतज़ार करता है.
लाइव स्ट्रीम को पहले से फ़ेच करने की सुविधा का इस्तेमाल करना
हमारा सुझाव है कि विज्ञापन ब्रेक खत्म होने के तुरंत बाद, अगले विज्ञापन ब्रेक को पहले से फ़ेच कर लें. इससे यह पक्का होता है कि प्री-फ़ेच विंडो के लिए ज़्यादा से ज़्यादा समय उपलब्ध हो. मान लें कि विज्ञापन ब्रेक के बीच पांच मिनट का समय है. विज्ञापन ब्रेक खत्म होने के बाद, अगले विज्ञापन ब्रेक का अनुरोध किया जा सकता है. इसके लिए, प्री-फ़ेच विंडो 290 सेकंड (पांच मिनट में से 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();
}