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 Android app.

Request custom video controls

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

First, create an instance of the VideoOptions.Builder(), and call setCustomControlsRequested() with a value of true. Next, build an instance of NativeAdOptions using this set of video options, and then build an AdLoader with the NativeAdOptions instance.

Java

VideoOptions videoOptions = new VideoOptions.Builder()
             .setCustomControlsRequested(true)
             .build();

NativeAdOptions adOptions = new NativeAdOptions.Builder()
                .setVideoOptions(videoOptions)
                .build();

// Included below is the sample ad unit for testing. Be sure to replace with
// your own ad unit when ready.
AdLoader.Builder builder = new AdLoader.Builder(context, "/6499/example/native-video");
builder.withNativeAdOptions(adOptions);

AdLoader adLoader = builder.build();
adLoader.loadAd(new PublisherAdRequest.Builder().build());

Kotlin

val videoOptions = VideoOptions.Builder()
                   .setCustomControlsRequested(true)
                   .build()

val adOptions = NativeAdOptions.Builder()
                .setVideoOptions(videoOptions)
                .build()

// Included below is the sample ad unit for testing. Be sure to replace with
// your own ad unit when ready.
val adLoader =  AdLoader.Builder(context,"/6499/example/native-video")
                .withNativeAdOptions(adOptions)
                .build()

adLoader.loadAd(PublisherAdRequest.Builder().build())

Check whether custom controls are enabled for an ad

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

Java

@Override
public void onNativeAdLoaded(UnifiedNativeAd nativeAd) {
  VideoController videoController = nativeAd.getVideoController();
  boolean canShowCustomControls = videoController.isCustomControlsEnabled();
}

Kotlin

NativeAppInstallAd.OnAppInstallAdLoadedListener { ad ->
             val videoController = ad.videoController
             val canShowCustomControls = videoController.isCustomControlsEnabled
}

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 VideoController.

These methods are:

  • mute(boolean mute) - Mute / unmute the video
  • play() - Play the video
  • pause() - Pause the video
  • isMuted() - Check the mute state of the video controller

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

Java Sample Kotlin Sample

Send feedback about...

Google Mobile Ads SDK for DoubleClick for Publishers Android Apps
Need help? Visit our support page.