পূর্বশর্ত
- নেটিভ বিজ্ঞাপন ফর্ম্যাটটি একীভূত করুন।
GADMediaContent সম্পর্কে
নেটিভ বিজ্ঞাপনগুলি একটি GADMediaContent ক্লাসে অ্যাক্সেস প্রদান করে যা মিডিয়া কন্টেন্ট সম্পর্কে তথ্য পেতে ব্যবহৃত হয় যা ভিডিও বা ছবি হতে পারে। এটি ভিডিও বিজ্ঞাপন প্লেব্যাক নিয়ন্ত্রণ করতেও ব্যবহৃত হয়, প্লেব্যাক ইভেন্টের জন্য শোনা। আপনি বিজ্ঞাপনের .mediaContent সম্পত্তির মাধ্যমে মিডিয়া কন্টেন্ট অবজেক্ট অ্যাক্সেস করতে পারেন।
GADMediaContent অবজেক্টে ভিডিওর আকৃতির অনুপাত এবং সময়কালের মতো তথ্য থাকে। নিচের স্নিপেটে দেখানো হয়েছে কিভাবে একটি নেটিভ বিজ্ঞাপনের আকৃতির অনুপাত এবং সময়কাল বের করতে হয়।
সুইফট
if myNativeAd.mediaContent.hasVideoContent { let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio) let duration = myNativeAd.mediaContent.duration }
অবজেক্টিভ-সি
if(myNativeAd.mediaContent.hasVideoContent) { CGFloat mediaAspectRatio = myNativeAd.mediaContent.aspectRatio; NSTimeInterval duration = myNativeAd.mediaContent.duration; }
GADVideoController সম্পর্কে
GADMediaContent অবজেক্টটিতে একটি GADVideoController অবজেক্টের রেফারেন্স থাকে। GADVideoController অবজেক্ট প্রকাশকদের ভিডিও ইভেন্টগুলিতে প্রতিক্রিয়া জানাতে দেয়।
এই GADVideoController অবজেক্টটি GADMediaContent.videoController কল করে পাওয়া যাবে।
ভিডিও ইভেন্টের জন্য কলব্যাক
নির্দিষ্ট ভিডিও ইভেন্ট পরিচালনা করার জন্য আপনাকে এমন একটি ক্লাস লিখতে হবে যা GADVideoControllerDelegate প্রোটোকল প্রয়োগ করে। প্রোটোকলের সমস্ত পদ্ধতি ঐচ্ছিক।
নিম্নলিখিত উদাহরণটি দেখায় কিভাবে ডেলিগেট প্রোটোকল বাস্তবায়ন করতে হয়:
সুইফট
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. } }
অবজেক্টিভ-সি
@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
আপনার নেটিভ বিজ্ঞাপনগুলি কীভাবে রেন্ডার করবেন সে সম্পর্কে আরও নির্দেশনার জন্য নেটিভ বিজ্ঞাপন নীতি এবং নির্দেশিকা পড়ুন।