পূর্বশর্ত
- নেটিভ বিজ্ঞাপন বিন্যাস একত্রিত করুন।
GADMmedia বিষয়বস্তু
নেটিভ বিজ্ঞাপনগুলি একটি 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 প্রোটোকল প্রয়োগ করে। প্রোটোকল পদ্ধতি সব ঐচ্ছিক.
নিম্নলিখিত উদাহরণ দেখায় কিভাবে প্রতিনিধি প্রোটোকল বাস্তবায়ন করতে হয়:
সুইফট
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
আপনার নেটিভ বিজ্ঞাপনগুলি কীভাবে রেন্ডার করবেন সে সম্পর্কে আরও নির্দেশনার জন্য নেটিভ বিজ্ঞাপন নীতি এবং নির্দেশিকা পড়ুন।