<br />

## Prerequisites

- Integrate the [Native ad format](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/native.md.txt).

## GADMediaContent

Native ads provide access to a `GADMediaContent` class that is used to get
information about media content which could be a video or an image. It is also
used to control the video ad playback listen for playback events. You can access
the media content object via the `.mediaContent` property on the ad.

The
[`GADMediaContent`](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADMediaContent.md.txt)
object contains information such as the aspect ratio and duration of video. The
snippet below shows how to get the aspect ratio and duration of a native ad.

### Swift

```swift
if myNativeAd.mediaContent.hasVideoContent {
  let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio)
  let duration = myNativeAd.mediaContent.duration
}
```

### Objective-C

```objective-c
if(myNativeAd.mediaContent.hasVideoContent) {
  CGFloat mediaAspectRatio = myNativeAd.mediaContent.aspectRatio;
  NSTimeInterval duration = myNativeAd.mediaContent.duration;
}
```

## GADVideoController

The `GADMediaContent` object has a reference to a
[`GADVideoController`](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADVideoController.md.txt)
object. The `GADVideoController` object allows publishers to respond to video
events.

Ads served through [line items](https://support.google.com/admanager/answer/82236) can
also be controlled with the `GADVideoController`.

This `GADVideoController` object can be obtained by calling
[`GADMediaContent.videoController`](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADMediaContent.md.txt#videocontroller).

## Callbacks for video events

To handle specific video events you need to write a class that implements the
[`GADVideoControllerDelegate`](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADVideoControllerDelegate.md.txt)
protocol. The methods of the protocol are all optional.

The following example shows how to implement the delegate protocol:

### Swift

```swift
class ViewController: NativeAdLoaderDelegate, VideoControllerDelegate {
  private var adLoader: AdLoader?

  func viewDidLoad() {
    super.viewDidLoad()

    let videoOptions = VideoOptions()
    videoOptions.customControlsRequested = true
    adLoader = AdLoader(
        adUnitID: "ca-app-pub-3940256099942544/3986624511",
        rootViewController: self,
        adTypes: [.native],
        options: [videoOptions])
    adLoader?.delegate = self
    adLoader?.load(AdManagerRequest())

  }

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

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

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

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

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

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

### Objective-C

```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:[GAMRequest 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
```

Read the [Native ads policies and
guidelines](https://support.google.com/admob/answer/6329638) for more guidance on how
to render your native ads.