Native ad videos
Native ads provide access to a MediaContent object that is used to get information about media content, which could be video or an image. It is also used to control video ad playback and listen for playback events. You can obtain the MediaContent object by calling get_media_content() on the loaded ad.
MediaContent
The MediaContent object contains information such as the aspect ratio and duration of a video. The following snippet shows how to get the aspect ratio and duration of a native ad.
Callbacks for video events
To handle specific video events, create a VideoLifecycleCallbacks object and assign it to the VideoController via video_lifecycle_callbacks. Then, set only the callbacks you care about.
Important Notes
[!WARNING] MediaView Requirement
If you load a video ad using the
SMALLtemplate, you will see an implementation issue/warning stating:MediaView not used for main image or video asset. Use MediaView instead of ImageView to show the main image or video asset.This happens because the official Google Mobile Ads SDK requires a visible
MediaViewto render the video, but the compactSMALLtemplate layout does not support or include a functional one by default. If your ad unit serves video ads, you must use theMEDIUMtemplate which includes a built-inMediaView.[!NOTE] MediaContent Values (Duration & Aspect Ratio)
Values like video duration and aspect ratio from the
MediaContentobject will return0.0if queried immediately inside theon_ad_loadedcallback. You must query them after callingrender_template(), once the ad view has been inflated and laid out.