Custom Video Controls

When displaying reserved native ads that include video assets, you can display your own video controls for play, pause, mute, and unmute. This guide outlines how to implement this feature in an iOS app.

Request custom video controls

The first step is to request custom video controls. This is done using the GADVideoOptions class.

Create an instance of GADVideoOptions and set customControlsRequested to YES. Next, use this instance as one of the options when initializing a GADAdLoader.

Swift

let videoOptions = GADVideoOptions()
videoOptions.customControlsRequested = true

// Included below is the sample ad unit for testing. Be sure to replace with
// your own ad unit when ready.
self.adLoader = GADAdLoader(adUnitID: "/6499/example/native-video",
                  rootViewController: self,
                             adTypes: adTypes,
                             options: [videoOptions])
adLoader.delegate = self
adLoader.load(DFPRequest())

Objective-C

GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
videoOptions.customControlsRequested = YES;

// Included below is the sample ad unit for testing. Be sure to replace with
// your own ad unit when ready.
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"/6499/example/native-video"
                                   rootViewController:self
                                              adTypes:adTypes
                                              options:@[ videoOptions ]];
self.adLoader.delegate = self;
[self.adLoader loadRequest:[DFPRequest request]];

Check whether custom controls are enabled for an ad

Because it's not known at request time whether the returned ad will allow custom video controls, you must check whether it has custom controls enabled.

Swift

func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADUnifiedNativeAd) {
        let videoController = nativeAd.mediaContent.videoController
        let canShowCustomControls = videoController?.customControlsEnabled() == true
}

Objective-C

- (void)adLoader:(GADAdLoader *)adLoader
    didReceiveNativeAd:(GADUnifiedNativeAd*)nativeAd {

  GADVideoController *videoController = nativeAd.mediaContent.videoController;
  BOOL canShowCustomControls = videoController.customControlsEnabled;

}

Implement custom controls

If the ad does have video content and custom controls are enabled, you should then display your custom controls along with the ad, as the ad will not show any controls itself. The controls can then call the relevant methods on the GADVideoController.

These methods are:

  • setMute:(BOOL)mute - Mute / unmute the video.
  • play - Play the video.
  • pause - Pause the video

For an implementation example, check out the Google Ad Manager Custom Controls example in the API Demo in our sample apps.

Objective-C Sample Swift Sample