Native video ads
Stay organized with collections
Save and categorize content based on your preferences.
Select platform:
Android
iOS
MediaContent
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
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.
Java
if (nativeAd.getMediaContent() != null) {
MediaContent mediaContent = nativeAd.getMediaContent();
float mediaAspectRatio = mediaContent.getAspectRatio();
if (mediaContent.hasVideoContent()) {
float duration = mediaContent.getDuration();
}
}
Kotlin
nativeAd.mediaContent?.let { mediaContent ->
val mediaAspectRatio: Float = mediaContent.aspectRatio
if (mediaContent.hasVideoContent()) {
val duration: Float = mediaContent.duration
}
}
Callbacks for video events
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.
Java
if (nativeAd.getMediaContent() != null) {
VideoController videoController = nativeAd.getMediaContent().getVideoController();
if (videoController != null) {
videoController.setVideoLifecycleCallbacks(
new VideoController.VideoLifecycleCallbacks() {
@Override
public void onVideoStart() {
Log.d(TAG, "Video started.");
}
@Override
public void onVideoPlay() {
Log.d(TAG, "Video played.");
}
@Override
public void onVideoPause() {
Log.d(TAG, "Video paused.");
}
@Override
public void onVideoEnd() {
Log.d(TAG, "Video ended.");
}
@Override
public void onVideoMute(boolean isMuted) {
Log.d(TAG, "Video isMuted: " + isMuted + ".");
}
});
}
}
Kotlin
val videoLifecycleCallbacks =
object : VideoController.VideoLifecycleCallbacks() {
override fun onVideoStart() {
Log.d(TAG, "Video started.")
}
override fun onVideoPlay() {
Log.d(TAG, "Video played.")
}
override fun onVideoPause() {
Log.d(TAG, "Video paused.")
}
override fun onVideoEnd() {
Log.d(TAG, "Video ended.")
}
override fun onVideoMute(isMuted: Boolean) {
Log.d(TAG, "Video isMuted: $isMuted.")
}
}
nativeAd.mediaContent?.videoController?.videoLifecycleCallbacks = videoLifecycleCallbacks
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-02 UTC.
[[["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-02 UTC."],[[["\u003cp\u003e\u003ccode\u003eMediaContent\u003c/code\u003e provides access to information about media in native ads, such as aspect ratio and duration for videos, and can be obtained using \u003ccode\u003eNativeAd.getMediaContent()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can control video playback and listen for events like start, play, pause, end, and mute using the \u003ccode\u003eVideoController\u003c/code\u003e and \u003ccode\u003eVideoLifecycleCallbacks\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo handle video events, extend the \u003ccode\u003eVideoLifecycleCallbacks\u003c/code\u003e class and override the desired callback methods to implement custom logic when these events occur.\u003c/p\u003e\n"]]],["Native ads utilize the `MediaContent` object to access information about media, including videos and images. Obtain this object using `NativeAd.getMediaContent()`. Key data like aspect ratio and video duration are accessible through this object. For video ads, extend `VideoLifecycleCallbacks` and use `setVideoLifecycleCallbacks()` to handle events such as start, play, pause, end, and mute. These events can be handled by overriding the corresponding callback functions.\n"],null,["Select platform: [Android](/admob/android/native/video-ads \"View this page for the Android platform docs.\") [iOS](/admob/ios/native/video-ads \"View this page for the iOS platform docs.\")\n\n\u003cbr /\u003e\n\nMediaContent Native ads provide access to a [`MediaContent`](/admob/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()`](/admob/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()`](/admob/android/reference/com/google/android/gms/ads/VideoController#setVideoLifecycleCallbacks(com.google.android.gms.ads.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"]]