नेटिव वीडियो विज्ञापन

ज़रूरी शर्तें

GADMediaContent

नेटिव विज्ञापनों से GADMediaContent क्लास का ऐक्सेस मिलता है. इसका इस्तेमाल उन मीडिया कॉन्टेंट के बारे में जानकारी पाने के लिए किया जाता है जो कोई वीडियो या इमेज हो सकते हैं. इसका इस्तेमाल प्लेबैक इवेंट के लिए, वीडियो विज्ञापन प्लेबैक सुनने को कंट्रोल करने के लिए भी किया जाता है. विज्ञापन पर मौजूद .mediaContent प्रॉपर्टी से, मीडिया कॉन्टेंट ऑब्जेक्ट को ऐक्सेस किया जा सकता है.

GADMediaContent ऑब्जेक्ट में, वीडियो का आसपेक्ट रेशियो (लंबाई-चौड़ाई का अनुपात) और वीडियो का कुल समय जैसी जानकारी शामिल होती है. नीचे दिए गए स्निपेट में नेटिव विज्ञापन का आसपेक्ट रेशियो और अवधि देखने का तरीका बताया गया है.

Swift

if myNativeAd.mediaContent.hasVideoContent {

  let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio)
  let duration = myNativeAd.mediaContent.duration
  ...
}

Objective-C

if(myNativeAd.mediaContent.hasVideoContent) {

  CGFloat mediaAspectRatio = myNativeAd.mediaContent.aspectRatio;
  NSTimeInterval duration = myNativeAd.mediaContent.duration;
   ...
}

GADVideoController

GADMediaContent ऑब्जेक्ट में, GADVideoController ऑब्जेक्ट का रेफ़रंस है. GADVideoController ऑब्जेक्ट की मदद से पब्लिशर, वीडियो इवेंट का जवाब दे सकते हैं.

यह GADVideoController ऑब्जेक्ट, GADMediaContent.videoController को कॉल करके पाया जा सकता है.

वीडियो इवेंट के लिए कॉलबैक

खास वीडियो इवेंट को मैनेज करने के लिए, आपको एक ऐसी क्लास लिखनी होगी जो GADVideoControllerDelegate प्रोटोकॉल लागू करती हो. प्रोटोकॉल के सभी तरीके ज़रूरी नहीं हैं.

यहां दिए गए उदाहरण में, डेलिगेट प्रोटोकॉल को लागू करने का तरीका बताया गया है:

Swift

class ViewController: GADNativeAdLoaderDelegate, GADVideoControllerDelegate {
  private var adLoader: GADAdLoader?

  func viewDidLoad() {
    super.viewDidLoad()

    let videoOptions = GADVideoOptions()
    videoOptions.customControlsRequested = true
    adLoader = GADAdLoader(
        adUnitID: "ca-app-pub-3940256099942544/3986624511",
        rootViewController: self,
        adTypes: [GADAdLoaderAdTypeNative],
        options: [videoOptions])
    adLoader?.delegate = self
    adLoader?.load(GADRequest())

  }

  func adLoader(
      _ adLoader: GADAdLoader?,
      didReceive nativeAd: GADNativeAd?
  ) {
    // Set the videoController's delegate to be notified of video events.
    nativeAd?.mediaContent.videoController.delegate = self
  }

  // GADVideoControllerDelegate methods
  func videoControllerDidPlayVideo(_ videoController: GADVideoController) {
    // Implement this method to receive a notification when the video controller
    // begins playing the ad.
  }

  func videoControllerDidPauseVideo(_ videoController: GADVideoController) {
    // Implement this method to receive a notification when the video controller
    // pauses the ad.
  }

  func videoControllerDidEndVideoPlayback(_ videoController: GADVideoController) {
    // Implement this method to receive a notification when the video controller
    // stops playing the ad.
  }

  func videoControllerDidMuteVideo(_ videoController: GADVideoController) {
    // Implement this method to receive a notification when the video controller
    // mutes the ad.
  }

  func videoControllerDidUnmuteVideo(_ videoController: GADVideoController) {
    // Implement this method to receive a notification when the video controller
    // unmutes the ad.
  }
}

Objective-C

@interface ViewController () <GADNativeAdLoaderDelegate,
    GADVideoControllerDelegate>
@property(nonatomic, strong) GADAdLoader *adLoader;

@end

@implementation ViewController
- (void)viewDidLoad {
  [super viewDidLoad];

  GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
  videoOptions.customControlsRequested = YES;
  self.adLoader =
      [[GADAdLoader alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511"
                         rootViewController:self
                                    adTypes:@[ GADAdLoaderAdTypeNative ]
                                    options:@[ videoOptions ]];
  self.adLoader.delegate = self;
  [self.adLoader loadRequest:[GADRequest request]];

}

- (void)adLoader:(GADAdLoader *)adLoader
    didReceiveNativeAd:(GADNativeAd *)nativeAd {
  // Set the videoController's delegate to be notified of video events.
  nativeAd.mediaContent.videoController.delegate = self;
}

// GADVideoControllerDelegate methods
- (void)videoControllerDidPlayVideo:(nonnull GADVideoController *)videoController {
  // Implement this method to receive a notification when the video controller
  // begins playing the ad.
}

- (void)videoControllerDidPauseVideo:(nonnull GADVideoController *)videoController {
  // Implement this method to receive a notification when the video controller
  // pauses the ad.
}

- (void)videoControllerDidEndVideoPlayback:(nonnull GADVideoController *)videoController {
  // Implement this method to receive a notification when the video controller
  // stops playing the ad.
}

- (void)videoControllerDidMuteVideo:(nonnull GADVideoController *)videoController {
  // Implement this method to receive a notification when the video controller
  // mutes the ad.
}

- (void)videoControllerDidUnmuteVideo:(nonnull GADVideoController *)videoController {
  // Implement this method to receive a notification when the video controller
  // unmutes the ad.
}

@end

अपने नेटिव विज्ञापनों को रेंडर करने के तरीके के बारे में ज़्यादा जानकारी के लिए, नेटिव विज्ञापन से जुड़ी नीतियां और दिशा-निर्देश पढ़ें.