โฆษณาวิดีโอเนทีฟ

ข้อกำหนดเบื้องต้น

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

อ่านนโยบายโฆษณาเนทีฟ หลักเกณฑ์สำหรับคำแนะนำเพิ่มเติมเกี่ยวกับวิธี เพื่อแสดงโฆษณาเนทีฟ