iOS के लिए, मीडिया विज्ञापन (IMA) SDK टूल.
यह गाइड उन IMA पब्लिशर के लिए है जिन्हें अपने मौजूदा IMA इंटिग्रेशन में, पिक्चर में पिक्चर की सुविधा जोड़नी है.
ज़रूरी शर्तें
अपने ऐप्लिकेशन में पिक्चर में पिक्चर की सुविधा जोड़ना
SDK टूल के 3.1.0 वर्शन से, IMA, iPad के लिए Apple के पिक्चर में पिक्चर मोड के साथ काम करता है. अपने ऐप्लिकेशन में पिक्चर में पिक्चर की सुविधा जोड़ने के लिए, आपको कुछ सेटिंग में बदलाव करना होगा. साथ ही, IMA की कुछ नई क्लास लागू करनी होंगी. इनके बारे में यहां बताया गया है.
बैकग्राउंड में वीडियो चलाने की अनुमति देने के लिए सेटिंग अपडेट करना
पिक्चर में पिक्चर मोड के लिए ज़रूरी है कि आपके ऐप्लिकेशन में, बैकग्राउंड में मीडिया चलाने की अनुमति हो.
यहां दिखाए गए तरीके से, ऑडियो, AirPlay, और पिक्चर में पिक्चर के लिए, बैकग्राउंड मोड को चालू पर सेट करें:

AVAudioSessionकी प्रॉपर्टी को बैकग्राउंड में वीडियो चलाने की अनुमति देने के लिए सेट करें. साथ ही,IMASettingsमें बैकग्राउंड में वीडियो चलाने की सुविधा चालू करें:... – (void)viewDidLoad { [super viewDidLoad]; self.playButton.layer.zPosition = MAXFLOAT; [[AVAudioSession sharedInstance] setActive:YES error:nil]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [self setupAdsLoader]; [self setUpContentPlayer]; } – (void)setupAdsLoader { IMASettings *settings = [[IMASettings alloc] init]; settings.enableBackgroundPlayback = YES; self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings]; self.adsLoader.delegate = self; }
पिक्चर में पिक्चर के लिए, iOS और IMA के नए ऑब्जेक्ट बनाना
पिक्चर में पिक्चर की सुविधा के लिए, Apple ने AVPictureInPictureController और AVPictureinPictureControllerDelegate क्लास जोड़ी हैं. वहीं, IMA ने IMAPictureInPictureProxy जोड़ा है. अपने प्रोजेक्ट में इन क्लास को शामिल करने के लिए, अपने कोड में ये स्टेटमेंट जोड़ें:
... @interface VideoViewController () <AVPictureInPictureControllerDelegate, IMAAdsLoaderDelegate, IMAAdsManagerDelegate, UIAlertViewDelegate> ... // PiP objects. @property(nonatomic, strong) IMAPictureInPictureProxy *pictureInPictureProxy; @property(nonatomic, strong) AVPictureInPictureController *pictureInPictureController; ... @end - (void)setUpContentPlayer { ... self.pictureInPictureProxy = [[IMAPictureInPictureProxy alloc] initWithAVPictureInPictureControllerDelegate:self]; self.pictureInPictureController = [[AVPictureInPictureController alloc] initWithPlayerLayer:self.contentPlayerLayer]; self.pictureInPictureController.delegate = self.pictureInPictureProxy; }
विज्ञापन के अनुरोध में बदलाव करना
एक और नया ऑब्जेक्ट बनाना होगा: IMAAVPlayerVideoDisplay. इसे आपके IMAAdsRequest कंस्ट्रक्टर को पास किया जाता है. इससे, SDK टूल को आपके वीडियो के पिक्चर में पिक्चर मोड में चलने के दौरान, PiP विंडो में विज्ञापन डालने की अनुमति मिलती है:
... - (void)requestAdsWithTag:(NSString *)adTagUrl { [self logMessage:@"Requesting ads"]; // Create an ad request with our ad tag, display container, and optional user context. IMAAdsRequest *request = [[IMAAdsRequest alloc] initWithAdTagUrl:adTagUrl adDisplayContainer:[self createAdDisplayContainer] avPlayerVideoDisplay:[[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:self.contentPlayer] pictureInPictureProxy:self.pictureInPictureProxy userContext:nil]; [self.adsLoader requestAdsWithRequest:request]; }
विज्ञापन दिखाना
IMA SDK टूल के विज्ञापन, पिक्चर में पिक्चर मोड के दौरान नहीं दिखाए जा सकते. इसलिए, आपको यह पक्का करना होगा कि [adsManager start] को सिर्फ़ तब कॉल किया जाए, जब आपका वीडियो स्टैंडर्ड प्लेबैक मोड में हो:
... - (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event { [self logMessage:@"AdsManager event (%s).", AdEventNames[event.type]]; // When the SDK notified you that ads have been loaded, play them. switch (event.type) { case kIMAAdEvent_LOADED: if (![self.pictureInPictureController isPictureInPictureActive]) { [adsManager start]; } break; ... default: break; } }
पिक्चर में पिक्चर मोड में जाना
अगर AVPlayerViewController के बिना AVPlayer का इस्तेमाल किया जा रहा है, तो आपको
पिक्चर में पिक्चर का बटन जोड़ना होगा. हमने अपने अडवांस
सैंपल
में, इस तरह का बटन जोड़ा है:
- (IBAction)onPipButtonClicked:(id)sender {
if ([self.pictureInPictureController isPictureInPictureActive]) {
[self.pictureInPictureController stopPictureInPicture];
} else {
[self.pictureInPictureController startPictureInPicture];
}
}
अक्सर पूछे जाने वाले सवाल
- वीडियो के पिक्चर में पिक्चर मोड में होने पर, विज्ञापन कैसे दिखाए जाएं?
- वीडियो के पिक्चर में पिक्चर मोड में होने पर, विज्ञापन नहीं दिखाए जा सकते. इन्हें सिर्फ़ स्टैंडर्ड प्लेबैक मोड में दिखाया जा सकता है.
- मेरे मौजूदा पिक्चर में पिक्चर इंटिग्रेशन के लिए,
self.pictureInPictureController.delegateको मेरी क्लास पर सेट करना ज़रूरी है. मैं पिक्चर में पिक्चर में IMA के विज्ञापन कैसे दिखाऊं और डेलिगेट कैसे बनूं? - IMA SDK टूल को, पिक्चर में पिक्चर मोड में विज्ञापन चलाने के लिए,
AVPictureinPictureControllerDelegateके मैसेज भी मिलने चाहिए. इसलिए, हम आपसेAVPictureinPictureControllerके डेलिगेट कोIMAPictureInPicturyProxyके इंस्टेंस पर सेट करने के लिए कहते हैं. यह प्रॉक्सी ऑब्जेक्ट,AVPictureinPictureControllerDelegateके सभी मैसेज आपके ऐप्लिकेशन को फ़ॉरवर्ड करता है. साथ ही, पिक्चर में पिक्चर की सुविधा चालू करने के लिए, IMA को कॉल भी फ़ॉरवर्ड करता है. ध्यान दें कि आपको अपने AVPlayerLayer के लिए, लोकल हैंडल भी बनाए रखना होगा.