IMA SDK ব্যবহার করে লাইভ স্ট্রিম এবং ভিডিও-অন-ডিমান্ড উভয় থেকেই অর্থ উপার্জন করা যায়। লাইভ স্ট্রিমের জন্য, প্রতিটি বিজ্ঞাপন বিরতির জন্য আপনাকে একটি নতুন বিজ্ঞাপনের অনুরোধ করতে হবে। এই অনুরোধগুলো পর্যায়ক্রমে করুন, যাতে আপনার সমস্ত দর্শক একই সময়ে বিজ্ঞাপনের জন্য অনুরোধ না করে এবং বিজ্ঞাপন সার্ভার(গুলো)কে ভারাক্রান্ত না করে।
এই কাজে সাহায্য করার জন্য, IMA SDK-তে AdsRequest.liveStreamPrefetchSeconds প্রপার্টিটি রয়েছে। আপনি AdsLoader.requestAds() কল করার পর অ্যাড সার্ভারে পৌঁছানোর আগে SDK সর্বোচ্চ কত সেকেন্ড অপেক্ষা করবে, তা এই প্রপার্টিটি নির্দিষ্ট করে দেয়। প্রকৃত অনুরোধের সময়টি র্যান্ডমাইজ করা হবে। উদাহরণস্বরূপ, যদি আপনি AdsRequest.liveStreamPrefetchSeconds ৩০-এ সেট করেন, তাহলে AdsLoader.requestAds() কল করার পর সার্ভারে অনুরোধটি পাঠানোর জন্য SDK ০ থেকে ৩০ সেকেন্ড অপেক্ষা করবে।
বাস্তবে লাইভ স্ট্রিম প্রি-ফেচ
আমরা সুপারিশ করি যে একটি বিজ্ঞাপন বিরতি শেষ হওয়ার সাথে সাথেই আপনার পরবর্তী বিজ্ঞাপন বিরতিটি প্রি-ফেচ করে নিন। এটি নিশ্চিত করে যে আপনার প্রি-ফেচ উইন্ডোর জন্য সর্বাধিক সময় পাওয়া যায়। ধরুন, দুটি বিজ্ঞাপন বিরতির মধ্যে আপনার ৫ মিনিটের ব্যবধান রয়েছে। যখন একটি বিজ্ঞাপন বিরতি শেষ হয়, আপনি ২৯০ সেকেন্ডের একটি প্রি-ফেচ উইন্ডো দিয়ে আপনার পরবর্তী বিজ্ঞাপন বিরতির জন্য অনুরোধ করতে পারেন (৫ মিনিট থেকে ১০ সেকেন্ড বাদ দিয়ে, যাতে প্রি-ফেচ উইন্ডোর শেষে পাঠানো অনুরোধগুলো সমাধান হওয়ার জন্য যথেষ্ট সময় পায়):
// 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();
}