تبلیغات ویدیویی بومی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پلتفرم را انتخاب کنید: Android iOS پیش نیازها
GADMediaContent
تبلیغات بومی دسترسی به کلاس GADMediaContent
را فراهم می کند که برای دریافت اطلاعات در مورد محتوای رسانه ای که می تواند یک ویدیو یا یک تصویر باشد، استفاده می شود. همچنین برای کنترل پخش آگهی ویدیویی گوش دادن برای رویدادهای پخش استفاده می شود. شما می توانید از طریق ویژگی .mediaContent
در آگهی به شی محتوای رسانه دسترسی داشته باشید.
شی GADMediaContent
حاوی اطلاعاتی مانند نسبت ابعاد و مدت زمان ویدیو است. قطعه زیر نحوه دریافت نسبت ابعاد و مدت زمان یک آگهی بومی را نشان می دهد.
سویفت
if myNativeAd.mediaContent.hasVideoContent {
let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio)
let duration = myNativeAd.mediaContent.duration
}
هدف-C
if(myNativeAd.mediaContent.hasVideoContent) {
CGFloat mediaAspectRatio = myNativeAd.mediaContent.aspectRatio;
NSTimeInterval duration = myNativeAd.mediaContent.duration;
}
GADVideoController
شی GADMediaContent
به یک شی GADVideoController
اشاره دارد. شی GADVideoController
به ناشران اجازه می دهد تا به رویدادهای ویدیویی پاسخ دهند.
تبلیغات ارائه شده از طریق آیتم های خط را می توان با GADVideoController
نیز کنترل کرد.
این شی GADVideoController
می توان با فراخوانی GADMediaContent.videoController
به دست آورد.
پاسخ به تماس برای رویدادهای ویدیویی
برای مدیریت رویدادهای ویدیویی خاص، باید کلاسی بنویسید که پروتکل GADVideoControllerDelegate
را پیاده سازی کند. روش های پروتکل همه اختیاری هستند.
مثال زیر نحوه پیاده سازی پروتکل delegate را نشان می دهد:
سویفت
class ViewController: NativeAdLoaderDelegate, VideoControllerDelegate {
private var adLoader: AdLoader?
func viewDidLoad() {
super.viewDidLoad()
let videoOptions = VideoOptions()
videoOptions.customControlsRequested = true
adLoader = AdLoader(
adUnitID: "ca-app-pub-3940256099942544/3986624511",
rootViewController: self,
adTypes: [.native],
options: [videoOptions])
adLoader?.delegate = self
adLoader?.load(AdManagerRequest())
}
func adLoader(
_ adLoader: AdLoader?,
didReceive nativeAd: NativeAd?
) {
// Set the videoController's delegate to be notified of video events.
nativeAd?.mediaContent.videoController.delegate = self
}
// VideoControllerDelegate methods
func videoControllerDidPlayVideo(_ videoController: VideoController) {
// Implement this method to receive a notification when the video controller
// begins playing the ad.
}
func videoControllerDidPauseVideo(_ videoController: VideoController) {
// Implement this method to receive a notification when the video controller
// pauses the ad.
}
func videoControllerDidEndVideoPlayback(_ videoController: VideoController) {
// Implement this method to receive a notification when the video controller
// stops playing the ad.
}
func videoControllerDidMuteVideo(_ videoController: VideoController) {
// Implement this method to receive a notification when the video controller
// mutes the ad.
}
func videoControllerDidUnmuteVideo(_ videoController: VideoController) {
// Implement this method to receive a notification when the video controller
// unmutes the ad.
}
}
هدف-C
@interface ViewController () <GADNativeAdLoaderDelegate,
GADVideoControllerDelegate>
@property(nonatomic, strong) GADAdLoader *adLoader;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
videoOptions.customControlsRequested = YES;
self.adLoader =
[[GADAdLoader alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511"
rootViewController:self
adTypes:@[ GADAdLoaderAdTypeNative ]
options:@[ videoOptions ]];
self.adLoader.delegate = self;
[self.adLoader loadRequest:[GAMRequest request]];
}
- (void)adLoader:(GADAdLoader *)adLoader
didReceiveNativeAd:(GADNativeAd *)nativeAd {
// Set the videoController's delegate to be notified of video events.
nativeAd.mediaContent.videoController.delegate = self;
}
// GADVideoControllerDelegate methods
- (void)videoControllerDidPlayVideo:(nonnull GADVideoController *)videoController {
// Implement this method to receive a notification when the video controller
// begins playing the ad.
}
- (void)videoControllerDidPauseVideo:(nonnull GADVideoController *)videoController {
// Implement this method to receive a notification when the video controller
// pauses the ad.
}
- (void)videoControllerDidEndVideoPlayback:(nonnull GADVideoController *)videoController {
// Implement this method to receive a notification when the video controller
// stops playing the ad.
}
- (void)videoControllerDidMuteVideo:(nonnull GADVideoController *)videoController {
// Implement this method to receive a notification when the video controller
// mutes the ad.
}
- (void)videoControllerDidUnmuteVideo:(nonnull GADVideoController *)videoController {
// Implement this method to receive a notification when the video controller
// unmutes the ad.
}
@end
برای راهنمایی بیشتر در مورد نحوه ارائه تبلیغات بومی خود ، خطمشیها و دستورالعملهای تبلیغات بومی را بخوانید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eNative ads provide a \u003ccode\u003eGADMediaContent\u003c/code\u003e object for accessing and controlling video or image content, including playback and information like aspect ratio and duration.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGADVideoController\u003c/code\u003e, accessible via \u003ccode\u003eGADMediaContent\u003c/code\u003e, allows publishers to manage video ad playback and respond to events like play, pause, and mute.\u003c/p\u003e\n"],["\u003cp\u003eTo receive video event notifications, implement the \u003ccode\u003eGADVideoControllerDelegate\u003c/code\u003e protocol in your class and set the \u003ccode\u003evideoController\u003c/code\u003e's delegate.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGADVideoControllerDelegate\u003c/code\u003e protocol includes optional methods like \u003ccode\u003evideoControllerDidPlayVideo\u003c/code\u003e and \u003ccode\u003evideoControllerDidPauseVideo\u003c/code\u003e for handling various video events.\u003c/p\u003e\n"],["\u003cp\u003ePublishers should adhere to the Native ads policies and guidelines for proper ad rendering.\u003c/p\u003e\n"]]],["Native ads use `GADMediaContent` to access media information, like aspect ratio and video duration. `GADVideoController`, accessible via `GADMediaContent`, allows publishers to respond to video events, including play, pause, mute, and unmute. To handle these events, implement the `GADVideoControllerDelegate` protocol, setting the video controller's delegate in the `adLoader`'s `didReceiveNativeAd` method. This method allows you to define actions for when a video starts, pauses, ends, or changes its mute state.\n"],null,["# Native video ads\n\nSelect 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\nPrerequisites\n-------------\n\n- Integrate the [Native ad format](/ad-manager/mobile-ads-sdk/ios/native).\n\nGADMediaContent\n---------------\n\nNative ads provide access to a `GADMediaContent` class that is used to get\ninformation about media content which could be a video or an image. It is also\nused to control the video ad playback listen for playback events. You can access\nthe media content object via the `.mediaContent` property on the ad.\n\nThe\n[`GADMediaContent`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADMediaContent)\nobject contains information such as the aspect ratio and duration of video. The\nsnippet below shows how to get the aspect ratio and duration of a native ad. \n\n### Swift\n\n```swift\nif myNativeAd.mediaContent.hasVideoContent {\n let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio)\n let duration = myNativeAd.mediaContent.duration\n}\n```\n\n### Objective-C\n\n```objective-c\nif(myNativeAd.mediaContent.hasVideoContent) {\n CGFloat mediaAspectRatio = myNativeAd.mediaContent.aspectRatio;\n NSTimeInterval duration = myNativeAd.mediaContent.duration;\n}\n```\n\nGADVideoController\n------------------\n\nThe `GADMediaContent` object has a reference to a\n[`GADVideoController`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADVideoController)\nobject. The `GADVideoController` object allows publishers to respond to video\nevents.\n\nAds served through [line items](//support.google.com/admanager/answer/82236) can\nalso be controlled with the `GADVideoController`.\n\nThis `GADVideoController` object can be obtained by calling\n[`GADMediaContent.videoController`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADMediaContent#videocontroller).\n\nCallbacks for video events\n--------------------------\n\nTo handle specific video events you need to write a class that implements the\n[`GADVideoControllerDelegate`](/ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADVideoControllerDelegate)\nprotocol. The methods of the protocol are all optional.\n\nThe following example shows how to implement the delegate protocol: \n\n### Swift\n\n```swift\nclass ViewController: NativeAdLoaderDelegate, VideoControllerDelegate {\n private var adLoader: AdLoader?\n\n func viewDidLoad() {\n super.viewDidLoad()\n\n let videoOptions = VideoOptions()\n videoOptions.customControlsRequested = true\n adLoader = AdLoader(\n adUnitID: \"ca-app-pub-3940256099942544/3986624511\",\n rootViewController: self,\n adTypes: [.native],\n options: [videoOptions])\n adLoader?.delegate = self\n adLoader?.load(AdManagerRequest())\n\n }\n\n func adLoader(\n _ adLoader: AdLoader?,\n didReceive nativeAd: NativeAd?\n ) {\n // Set the videoController's delegate to be notified of video events.\n nativeAd?.mediaContent.videoController.delegate = self\n }\n\n // VideoControllerDelegate methods\n func videoControllerDidPlayVideo(_ videoController: VideoController) {\n // Implement this method to receive a notification when the video controller\n // begins playing the ad.\n }\n\n func videoControllerDidPauseVideo(_ videoController: VideoController) {\n // Implement this method to receive a notification when the video controller\n // pauses the ad.\n }\n\n func videoControllerDidEndVideoPlayback(_ videoController: VideoController) {\n // Implement this method to receive a notification when the video controller\n // stops playing the ad.\n }\n\n func videoControllerDidMuteVideo(_ videoController: VideoController) {\n // Implement this method to receive a notification when the video controller\n // mutes the ad.\n }\n\n func videoControllerDidUnmuteVideo(_ videoController: VideoController) {\n // Implement this method to receive a notification when the video controller\n // unmutes the ad.\n }\n}\n```\n\n### Objective-C\n\n```objective-c\n@interface ViewController () \u003cGADNativeAdLoaderDelegate,\n GADVideoControllerDelegate\u003e\n@property(nonatomic, strong) GADAdLoader *adLoader;\n\n@end\n\n@implementation ViewController\n- (void)viewDidLoad {\n [super viewDidLoad];\n\n GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];\n videoOptions.customControlsRequested = YES;\n self.adLoader =\n [[GADAdLoader alloc] initWithAdUnitID:@\"ca-app-pub-3940256099942544/3986624511\"\n rootViewController:self\n adTypes:@[ GADAdLoaderAdTypeNative ]\n options:@[ videoOptions ]];\n self.adLoader.delegate = self;\n [self.adLoader loadRequest:[GAMRequest request]];\n\n}\n\n- (void)adLoader:(GADAdLoader *)adLoader\n didReceiveNativeAd:(GADNativeAd *)nativeAd {\n // Set the videoController's delegate to be notified of video events.\n nativeAd.mediaContent.videoController.delegate = self;\n}\n\n// GADVideoControllerDelegate methods\n- (void)videoControllerDidPlayVideo:(nonnull GADVideoController *)videoController {\n // Implement this method to receive a notification when the video controller\n // begins playing the ad.\n}\n\n- (void)videoControllerDidPauseVideo:(nonnull GADVideoController *)videoController {\n // Implement this method to receive a notification when the video controller\n // pauses the ad.\n}\n\n- (void)videoControllerDidEndVideoPlayback:(nonnull GADVideoController *)videoController {\n // Implement this method to receive a notification when the video controller\n // stops playing the ad.\n}\n\n- (void)videoControllerDidMuteVideo:(nonnull GADVideoController *)videoController {\n // Implement this method to receive a notification when the video controller\n // mutes the ad.\n}\n\n- (void)videoControllerDidUnmuteVideo:(nonnull GADVideoController *)videoController {\n // Implement this method to receive a notification when the video controller\n // unmutes the ad.\n}\n\n@end\n```\n\nRead the [Native ads policies and\nguidelines](//support.google.com/admob/answer/6329638) for more guidance on how\nto render your native ads."]]