Native ads and custom native ad formats
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
NativeAd.getMediaContent().
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.
To handle specific video events, write a class that extends the abstract
VideoLifecycleCallbacks class, and call
setVideoLifecycleCallbacks()
on the VideoController. Then, override only the callbacks you care about.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eNative ads provide a \u003ccode\u003eMediaContent\u003c/code\u003e object to access and control video or image content within the ad.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve information like aspect ratio and duration from the \u003ccode\u003eMediaContent\u003c/code\u003e object for video ads.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can monitor and respond to video playback events (start, play, pause, end, mute) using \u003ccode\u003eVideoLifecycleCallbacks\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/native/video-ads \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/native/video-ads \"View this page for the iOS platform docs.\")\n\n\u003cbr /\u003e\n\nMediaContent Native ads and custom native ad formats provide access to a [`MediaContent`](/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/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 [`NativeAd.getMediaContent()`](/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/nativead/NativeAd#getMediaContent()).\n\n\u003cbr /\u003e\n\nThe `MediaContent` object contains information such as the aspect ratio and\nduration of a video. The following snippet shows how to get the aspect ratio and\nduration of a native ad. \n\nJava \n\n if (nativeAd.getMediaContent() != null) {\n MediaContent mediaContent = nativeAd.getMediaContent();\n float mediaAspectRatio = mediaContent.getAspectRatio();\n if (mediaContent.hasVideoContent()) {\n float duration = mediaContent.getDuration();\n }\n } \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeVideoAdsSnippets.java#L31-L37\n\nKotlin \n\n nativeAd.mediaContent?.let { mediaContent -\u003e\n val mediaAspectRatio: Float = mediaContent.aspectRatio\n if (mediaContent.hasVideoContent()) {\n val duration: Float = mediaContent.duration\n }\n } \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeVideoAdsSnippets.kt#L28-L33\n\nCallbacks for video events\n\nTo handle specific video events, write a class that extends the abstract\n`VideoLifecycleCallbacks` class, and call\n[`setVideoLifecycleCallbacks()`](/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/common/VideoController#etVideoLifecycleCallbacks(com.google.android.libraries.ads.mobile.sdk.common.VideoController.VideoLifecycleCallbacks))\non the `VideoController`. Then, override only the callbacks you care about. \n\nJava \n\n if (nativeAd.getMediaContent() != null) {\n VideoController videoController = nativeAd.getMediaContent().getVideoController();\n if (videoController != null) {\n videoController.setVideoLifecycleCallbacks(\n new VideoController.VideoLifecycleCallbacks() {\n @Override\n public void onVideoStart() {\n Log.d(TAG, \"Video started.\");\n }\n\n @Override\n public void onVideoPlay() {\n Log.d(TAG, \"Video played.\");\n }\n\n @Override\n public void onVideoPause() {\n Log.d(TAG, \"Video paused.\");\n }\n\n @Override\n public void onVideoEnd() {\n Log.d(TAG, \"Video ended.\");\n }\n\n @Override\n public void onVideoMute(boolean isMuted) {\n Log.d(TAG, \"Video isMuted: \" + isMuted + \".\");\n }\n });\n }\n } \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeVideoAdsSnippets.java#L43-L74\n\nKotlin \n\n val videoLifecycleCallbacks =\n object : VideoController.VideoLifecycleCallbacks() {\n override fun onVideoStart() {\n Log.d(TAG, \"Video started.\")\n }\n\n override fun onVideoPlay() {\n Log.d(TAG, \"Video played.\")\n }\n\n override fun onVideoPause() {\n Log.d(TAG, \"Video paused.\")\n }\n\n override fun onVideoEnd() {\n Log.d(TAG, \"Video ended.\")\n }\n\n override fun onVideoMute(isMuted: Boolean) {\n Log.d(TAG, \"Video isMuted: $isMuted.\")\n }\n }\n nativeAd.mediaContent?.videoController?.videoLifecycleCallbacks = videoLifecycleCallbacks \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeVideoAdsSnippets.kt#L39-L61"]]