โฆษณาวิดีโอเนทีฟ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เลือกแพลตฟอร์ม:
Android
iOS
ข้อกำหนดเบื้องต้น
GADMediaContent
โฆษณาเนทีฟให้สิทธิ์เข้าถึงคลาส GADMediaContent
ที่ใช้เพื่อรับข้อมูลเกี่ยวกับเนื้อหาสื่อ ซึ่งอาจเป็นวิดีโอหรือรูปภาพ นอกจากนี้ยังใช้เพื่อควบคุมการเล่นโฆษณาวิดีโอและฟังเหตุการณ์การเล่นด้วย
คุณเข้าถึงออบเจ็กต์เนื้อหาสื่อได้ผ่านพร็อพเพอร์ตี้ .mediaContent
ในโฆษณา
ออบเจ็กต์
GADMediaContent
มีข้อมูล เช่น สัดส่วนภาพและระยะเวลาของวิดีโอ
ข้อมูลโค้ดด้านล่างแสดงวิธีรับสัดส่วนภาพและระยะเวลาของโฆษณาเนทีฟ
Swift
if myNativeAd.mediaContent.hasVideoContent {
let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio)
let duration = myNativeAd.mediaContent.duration
}
Objective-C
if(myNativeAd.mediaContent.hasVideoContent) {
CGFloat mediaAspectRatio = myNativeAd.mediaContent.aspectRatio;
NSTimeInterval duration = myNativeAd.mediaContent.duration;
}
GADVideoController
ออบเจ็กต์ GADMediaContent
มีการอ้างอิงถึงออบเจ็กต์
GADVideoController
ออบเจ็กต์ GADVideoController
ช่วยให้ผู้เผยแพร่โฆษณาสามารถตอบสนองต่อเหตุการณ์วิดีโอ
ได้
คุณรับGADVideoController
ออบเจ็กต์นี้ได้โดยการเรียกใช้
GADMediaContent.videoController
Callback สำหรับเหตุการณ์วิดีโอ
หากต้องการจัดการเหตุการณ์วิดีโอที่เฉพาะเจาะจง คุณต้องเขียนคลาสที่ใช้โปรโตคอล
GADVideoControllerDelegate
วิธีการของโปรโตคอลทั้งหมดเป็นค่าที่ไม่บังคับ
ตัวอย่างต่อไปนี้แสดงวิธีใช้โปรโตคอลการมอบสิทธิ์
Swift
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(Request())
}
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.
}
}
Objective-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:[GADRequest 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
อ่านนโยบายและหลักเกณฑ์สำหรับโฆษณาเนทีฟเพื่อดูคำแนะนำเพิ่มเติมเกี่ยวกับวิธีแสดงโฆษณาเนทีฟ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-02 UTC
[null,null,["อัปเดตล่าสุด 2025-09-02 UTC"],[[["\u003cp\u003eNative ads provide a \u003ccode\u003eGADMediaContent\u003c/code\u003e class for accessing and controlling video or image content, including playback and event listening.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGADMediaContent\u003c/code\u003e object offers details like aspect ratio and duration, accessible through the ad's \u003ccode\u003e.mediaContent\u003c/code\u003e property.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eGADVideoController\u003c/code\u003e, linked to \u003ccode\u003eGADMediaContent\u003c/code\u003e, enables publishers to manage video events through a delegate protocol.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGADVideoControllerDelegate\u003c/code\u003e protocol provides optional methods for responding to various video events, such as play, pause, end, mute, and unmute.\u003c/p\u003e\n"]]],["Native ads utilize `GADMediaContent` to access media information, like aspect ratio and video duration, via the `.mediaContent` property. The `GADVideoController` object, accessed through `GADMediaContent.videoController`, handles video events. Implement the `GADVideoControllerDelegate` protocol to receive callbacks for events like play, pause, mute, and unmute. To use this you should integrate the Native ad format, and implement the necessary methods to be notified of the ad's video events.\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\nPrerequisites\n\n- Integrate the [Native ad format](/admob/ios/native).\n\nGADMediaContent\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`](/admob/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\nSwift \n\n```swift\nif myNativeAd.mediaContent.hasVideoContent {\n let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio)\n let duration = myNativeAd.mediaContent.duration\n}\n```\n\nObjective-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\nThe `GADMediaContent` object has a reference to a\n[`GADVideoController`](/admob/ios/api/reference/Classes/GADVideoController)\nobject. The `GADVideoController` object allows publishers to respond to video\nevents.\n\nThis `GADVideoController` object can be obtained by calling\n[`GADMediaContent.videoController`](/admob/ios/api/reference/Classes/GADMediaContent#videocontroller).\n\nCallbacks for video events\n\nTo handle specific video events you need to write a class that implements the\n[`GADVideoControllerDelegate`](/admob/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\nSwift \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(Request())\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\nObjective-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:[GADRequest 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."]]